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