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
|
||||
name = marc
|
||||
version = 2.11.0
|
||||
version = 2.12.0
|
||||
|
||||
org.gradle.warning.mode = ALL
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package org.xbib.marc;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.xbib.marc.dialects.mab.MabSubfieldControl;
|
||||
import org.xbib.marc.label.RecordLabel;
|
||||
|
||||
|
@ -609,6 +610,7 @@ public class MarcField implements Comparable<MarcField> {
|
|||
* @return this builder
|
||||
*/
|
||||
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()
|
||||
.filter(sf -> !subfieldIds.contains(sf.id))
|
||||
.collect(Collectors.toCollection(LinkedList::new));
|
||||
|
@ -617,6 +619,22 @@ public class MarcField implements Comparable<MarcField> {
|
|||
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.
|
||||
* @param field the MARC field to copy
|
||||
|
@ -785,7 +803,7 @@ public class MarcField implements Comparable<MarcField> {
|
|||
|
||||
private final String id;
|
||||
|
||||
private final String value;
|
||||
private String value;
|
||||
|
||||
private Subfield(String id, String value) {
|
||||
this.id = id;
|
||||
|
@ -808,6 +826,10 @@ public class MarcField implements Comparable<MarcField> {
|
|||
return value;
|
||||
}
|
||||
|
||||
private void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Subfield && toString().equals(obj.toString());
|
||||
|
|
Loading…
Reference in a new issue