add replace subfield method to MarcField builder
This commit is contained in:
parent
ff3d3b5535
commit
0f251114a3
2 changed files with 24 additions and 2 deletions
2
gradle.properties
vendored
2
gradle.properties
vendored
|
@ -1,5 +1,5 @@
|
||||||
group = org.xbib
|
group = org.xbib
|
||||||
name = marc
|
name = marc
|
||||||
version = 2.11.0
|
version = 2.12.0
|
||||||
|
|
||||||
org.gradle.warning.mode = ALL
|
org.gradle.warning.mode = ALL
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.xbib.marc;
|
package org.xbib.marc;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import org.xbib.marc.dialects.mab.MabSubfieldControl;
|
import org.xbib.marc.dialects.mab.MabSubfieldControl;
|
||||||
import org.xbib.marc.label.RecordLabel;
|
import org.xbib.marc.label.RecordLabel;
|
||||||
|
|
||||||
|
@ -609,6 +610,7 @@ public class MarcField implements Comparable<MarcField> {
|
||||||
* @return this builder
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
public Builder removeSubfields(Set<String> subfieldIds) {
|
public Builder removeSubfields(Set<String> subfieldIds) {
|
||||||
|
// create a new subfield list and replace the whole list by a filtered list
|
||||||
LinkedList<Subfield> list = subfields.stream()
|
LinkedList<Subfield> list = subfields.stream()
|
||||||
.filter(sf -> !subfieldIds.contains(sf.id))
|
.filter(sf -> !subfieldIds.contains(sf.id))
|
||||||
.collect(Collectors.toCollection(LinkedList::new));
|
.collect(Collectors.toCollection(LinkedList::new));
|
||||||
|
@ -617,6 +619,22 @@ public class MarcField implements Comparable<MarcField> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In-place replacement of all subfields with a given ID.
|
||||||
|
* @param subfieldId the subfield ID
|
||||||
|
* @param newValue the new value, must be non-null
|
||||||
|
* @return this builder
|
||||||
|
*/
|
||||||
|
public Builder replace(String subfieldId, String newValue) {
|
||||||
|
Objects.requireNonNull(newValue);
|
||||||
|
for (Subfield subfield : subfields) {
|
||||||
|
if (subfield.getId().equals(subfieldId)) {
|
||||||
|
subfield.setValue(newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy a MARC field into this builder.
|
* Copy a MARC field into this builder.
|
||||||
* @param field the MARC field to copy
|
* @param field the MARC field to copy
|
||||||
|
@ -785,7 +803,7 @@ public class MarcField implements Comparable<MarcField> {
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
private final String value;
|
private String value;
|
||||||
|
|
||||||
private Subfield(String id, String value) {
|
private Subfield(String id, String value) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -808,6 +826,10 @@ public class MarcField implements Comparable<MarcField> {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return obj instanceof Subfield && toString().equals(obj.toString());
|
return obj instanceof Subfield && toString().equals(obj.toString());
|
||||||
|
|
Loading…
Reference in a new issue