allow null marcFields in MarcRecord
This commit is contained in:
parent
e45038d31a
commit
dd40b8918e
3 changed files with 19 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
group = org.xbib
|
||||
name = marc
|
||||
version = 2.9.5
|
||||
version = 2.9.6
|
||||
|
||||
org.gradle.warning.mode = ALL
|
||||
|
|
|
@ -22,13 +22,15 @@ jar {
|
|||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
dependsOn classes
|
||||
classifier 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
dependsOn javadoc
|
||||
classifier 'javadoc'
|
||||
from sourceSets.main.allSource
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifacts {
|
||||
|
|
|
@ -49,11 +49,10 @@ public class MarcRecord implements Map<String, Object> {
|
|||
|
||||
private transient RecordLabel recordLabel;
|
||||
|
||||
private final transient List<MarcField> marcFields;
|
||||
private transient List<MarcField> marcFields;
|
||||
|
||||
private MarcRecord(Map<String, Object> delegate) {
|
||||
this.delegate = delegate;
|
||||
this.marcFields = new LinkedList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,6 +106,7 @@ public class MarcRecord implements Map<String, Object> {
|
|||
RecordLabel recordLabel,
|
||||
Collection<String> privateTags) {
|
||||
MarcRecord marcRecord = new MarcRecord(map);
|
||||
marcRecord.marcFields = new LinkedList<>();
|
||||
Set<String> forbidden = new HashSet<>(privateTags);
|
||||
forbidden.add(formatTag);
|
||||
forbidden.add(typeTag);
|
||||
|
@ -214,7 +214,9 @@ public class MarcRecord implements Map<String, Object> {
|
|||
* @param handler the handler
|
||||
*/
|
||||
public void all(Predicate<? super MarcField> predicate, MarcFieldHandler handler) {
|
||||
marcFields.stream().filter(predicate).forEach(handler::field);
|
||||
if (marcFields != null) {
|
||||
marcFields.stream().filter(predicate).forEach(handler::field);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -298,7 +300,9 @@ public class MarcRecord implements Map<String, Object> {
|
|||
* @param handler the handler
|
||||
*/
|
||||
public void first(Predicate<? super MarcField> predicate, MarcFieldHandler handler) {
|
||||
marcFields.stream().filter(predicate).findFirst().ifPresent(handler::field);
|
||||
if (marcFields != null) {
|
||||
marcFields.stream().filter(predicate).findFirst().ifPresent(handler::field);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -350,7 +354,9 @@ public class MarcRecord implements Map<String, Object> {
|
|||
* @param handler the handler
|
||||
*/
|
||||
public void any(Predicate<? super MarcField> predicate, MarcFieldHandler handler) {
|
||||
marcFields.stream().filter(predicate).findAny().ifPresent(handler::field);
|
||||
if (marcFields != null) {
|
||||
marcFields.stream().filter(predicate).findAny().ifPresent(handler::field);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -437,7 +443,7 @@ public class MarcRecord implements Map<String, Object> {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (recordLabel.toString() + marcFields.toString()).hashCode();
|
||||
return (recordLabel.toString() + (marcFields != null ? marcFields.toString() : "")).hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -447,6 +453,9 @@ public class MarcRecord implements Map<String, Object> {
|
|||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> createMapFromMarcFields(boolean stable) {
|
||||
Map<String, Object> map = stable ? new TreeMap<>() : new LinkedHashMap<>();
|
||||
if (marcFields == null) {
|
||||
return map;
|
||||
}
|
||||
for (MarcField marcField : marcFields) {
|
||||
String tag = marcField.getTag();
|
||||
int repeat;
|
||||
|
|
Loading…
Reference in a new issue