add convenience method

This commit is contained in:
Jörg Prante 2022-11-23 17:57:36 +01:00
parent 8192830b75
commit 216031848e
2 changed files with 15 additions and 1 deletions

View file

@ -1,5 +1,5 @@
group = org.xbib group = org.xbib
name = marc name = marc
version = 2.9.7 version = 2.9.8
org.gradle.warning.mode = ALL org.gradle.warning.mode = ALL

View file

@ -451,6 +451,20 @@ public class MarcField implements Comparable<MarcField> {
return this; return this;
} }
/**
* Convenience method to add a subfield only if the value is not null.
* @param subfieldId the dubfield ID
* @param value the subfield value
* @return this builder
*/
public Builder subfieldIfNotNull(String subfieldId, String value) {
if (value != null) {
String id = validator.validateSubfieldId(subfieldId);
subfields.add(new Subfield(id, value));
}
return this;
}
/** /**
* Add subfield ID without a value. * Add subfield ID without a value.
* @param subfieldId the subfield ID * @param subfieldId the subfield ID