-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathBag.java
More file actions
171 lines (140 loc) · 4.49 KB
/
Bag.java
File metadata and controls
171 lines (140 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package gov.loc.repository.bagit.domain;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
/**
* The main representation of the bagit spec.
*/
public final class Bag {
//The original version of the bag
private Version version = new Version(-1, -1);
//from the bagit.txt or UTF-8 for new bags
private Charset fileEncoding = StandardCharsets.UTF_8;
//equivalent to the manifest-<ALG>.txt files
private Set<Manifest> payLoadManifests = new HashSet<>();
//equivalent to the tagmanifest-<ALG>.txt files
private Set<Manifest> tagManifests = new HashSet<>();
//equivalent to the fetch.txt
private List<FetchItem> itemsToFetch = new ArrayList<>();
//equivalent to the bag-info.txt
private List<SimpleImmutableEntry<String, String>> metadata = new ArrayList<>();
//the current location of the bag on the filesystem
private Path rootDir;
/**
* empty bag with an invalid version
*/
public Bag(){
//intentionally empty
}
/**
* empty bag with the specified bag version
*
* @param version the version of the bag
*/
public Bag(final Version version){
this.version = version;
}
/**
* Create a new bag with the same values as the supplied bag
*
* @param bag the bag to clone
*/
public Bag(final Bag bag){
this.version = bag.getVersion();
this.fileEncoding = bag.fileEncoding;
this.itemsToFetch = bag.getItemsToFetch();
this.metadata = bag.getMetadata();
this.payLoadManifests = bag.getPayLoadManifests();
this.tagManifests = bag.getTagManifests();
this.rootDir = bag.getRootDir();
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder(95);
sb.append("Bag [version=").append(version)
.append(", fileEncoding=").append(fileEncoding)
.append(", payLoadManifests=[");
for(final Manifest payloadManifest : payLoadManifests){
sb.append(payloadManifest).append(' ');
}
sb.append("], tagManifests=[");
for(final Manifest tagManifest : tagManifests){
sb.append(tagManifest).append(' ');
}
sb.append("], itemsToFetch=").append(itemsToFetch)
.append(", metadata=").append(metadata).append(']');
return sb.toString();
}
@Override
public int hashCode() {
return Objects.hash(version) + Objects.hash(fileEncoding) + Objects.hash(payLoadManifests) +
Objects.hash(tagManifests) + Objects.hash(itemsToFetch) + Objects.hash(metadata);
}
@Override
public boolean equals(final Object obj) {
if (this == obj){
return true;
}
if (obj == null){
return false;
}
if (!(obj instanceof Bag)){
return false;
}
final Bag other = (Bag) obj;
return Objects.equals(this.version, other.getVersion()) &&
Objects.equals(this.fileEncoding, other.getFileEncoding()) &&
Objects.equals(this.payLoadManifests, other.getPayLoadManifests()) &&
Objects.equals(this.tagManifests, other.getTagManifests()) &&
Objects.equals(this.itemsToFetch, other.getItemsToFetch()) &&
Objects.equals(this.metadata, other.getMetadata());
}
public Version getVersion(){
return version;
}
public Set<Manifest> getPayLoadManifests() {
return payLoadManifests;
}
public void setPayLoadManifests(final Set<Manifest> payLoadManifests) {
this.payLoadManifests = payLoadManifests;
}
public Set<Manifest> getTagManifests() {
return tagManifests;
}
public void setTagManifests(final Set<Manifest> tagManifests) {
this.tagManifests = tagManifests;
}
public List<FetchItem> getItemsToFetch() {
return itemsToFetch;
}
public void setItemsToFetch(final List<FetchItem> itemsToFetch) {
this.itemsToFetch = itemsToFetch;
}
public List<SimpleImmutableEntry<String, String>> getMetadata() {
return metadata;
}
public void setMetadata(final List<SimpleImmutableEntry<String, String>> metadata) {
this.metadata = metadata;
}
public Charset getFileEncoding() {
return fileEncoding;
}
public void setFileEncoding(final Charset fileEncoding) {
this.fileEncoding = fileEncoding;
}
public Path getRootDir() {
return rootDir;
}
public void setRootDir(final Path rootDir) {
this.rootDir = rootDir;
}
public void setVersion(final Version version) {
this.version = version;
}
}