Class DataField
- java.lang.Object
-
- org.marc4j.marc.VariableField
-
- org.marc4j.marc.DataField
-
- All Implemented Interfaces:
Serializable
,Cloneable
public class DataField extends VariableField implements Serializable, Cloneable
DataField
defines behavior for a data field (tag 010-999).Data fields are variable fields identified by tags beginning with ASCII numeric values other than two zero's. Data fields contain indicators, subfield codes, data and a field terminator. The structure of a data field according to the MARC standard is as follows:
INDICATOR_1 INDICATOR_2 DELIMITER DATA_ELEMENT_IDENTIFIER_1 DATA_ELEMENT_1 ... DELIMITER DATA_ELEMENT_IDENTIFIER_n DATA_ELEMENT_n FT
This structure is returned by the
marshal()
method.- Author:
- Bas Peters
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.marc4j.marc.VariableField
EMPTY_ID
-
-
Constructor Summary
Constructors Constructor Description DataField()
Default constructor.DataField(String tag)
Creates a newDataField
instance and registers the tag name.DataField(String tag, char ind1, char ind2)
Creates a newDataField
and sets the tag name and the first and second indicator.DataField(String tag, char ind1, char ind2, Long id)
Creates a newDataField
and sets the tag name and the first and second indicator, and the idDataField(DataField other)
Copy constructor Copy id attribute, so if you don't want has the same, usecopy(DataField)
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(Subfield subfield)
Deprecated.void
addSubfield(int index, Subfield subfield)
Adds a newSubfield
instance at the specified position.void
addSubfield(Subfield subfield)
Adds a newSubfield
instance to the collection of data elements.Object
clone()
Deprecated.static DataField
copy(DataField original)
Creates a copy of the original instance without copy the id attribute.boolean
equals(Object obj)
boolean
find(Pattern pattern)
Returnstrue
if a match is found for the supplied regular expression pattern; else,false
.Optional<Subfield>
getFirstSubfield(char code)
Returns the firstSubfield
with the suppliedchar
code.char
getIndicator1()
Returns the first indicator.char
getIndicator2()
Returns the second indicator.int
getLength()
Returns the length of the serialized form of the current data field.Subfield
getSubfield(char code)
Deprecated.List<Subfield>
getSubfieldList()
Deprecated.Use {getSubfields()
List<Subfield>
getSubfields()
Returns the collection of SubfieldsStream<Subfield>
getSubfields(char code)
int
hashCode()
boolean
hasSubfield(char code)
Returns true if there is a subfield with the given identifier.String
marshal()
Returns aString
representation for a data field following the structure of a MARC data field.void
removeSubfield(Subfield subfield)
Removes aSubfield
from the field.void
setIndicator1(char ind1)
Registers the first indicator value.void
setIndicator2(char ind2)
Registers the second indicator value.void
setSubfieldList(List<Subfield> subfields)
Deprecated.Use {setSubfields(List)
void
setSubfields(List<Subfield> subfields)
Sets the collection of data elements.void
setTag(String tag)
Registers the tag.String
toString()
-
Methods inherited from class org.marc4j.marc.VariableField
getId, getTag, setId
-
-
-
-
Constructor Detail
-
DataField
public DataField()
Default constructor.
-
DataField
public DataField(String tag)
Creates a newDataField
instance and registers the tag name.- Parameters:
tag
- The tag name
-
DataField
public DataField(String tag, char ind1, char ind2)
Creates a newDataField
and sets the tag name and the first and second indicator.- Parameters:
tag
- The tag nameind1
- The first indicatorind2
- The second indicator
-
DataField
public DataField(String tag, char ind1, char ind2, Long id)
Creates a newDataField
and sets the tag name and the first and second indicator, and the id- Parameters:
tag
- The tag nameind1
- The first indicatorind2
- The second indicatorid
- The id for the DataField
-
DataField
public DataField(DataField other)
Copy constructor Copy id attribute, so if you don't want has the same, usecopy(DataField)
.- Parameters:
other
- Another instance ofDataField
, where to copy all the values
-
-
Method Detail
-
copy
public static DataField copy(DataField original)
Creates a copy of the original instance without copy the id attribute.- Parameters:
original
- Instance to copy.- Returns:
- new copy of original instance without the id attribute.
-
find
public boolean find(Pattern pattern)
Returnstrue
if a match is found for the supplied regular expression pattern; else,false
.- Specified by:
find
in classVariableField
- Parameters:
pattern
- An instance of a compiled Pattern to use as matcher
-
add
@Deprecated public void add(Subfield subfield)
Deprecated.Adds a new
Subfield
instance to the collection of data elements.- Parameters:
subfield
- the data element- See Also:
Subfield
-
addSubfield
public void addSubfield(Subfield subfield)
Adds a newSubfield
instance to the collection of data elements.
-
addSubfield
public void addSubfield(int index, Subfield subfield)
Adds a newSubfield
instance at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
-
removeSubfield
public void removeSubfield(Subfield subfield)
Removes aSubfield
from the field.- Parameters:
subfield
- The subfield to remove from the field.
-
getSubfield
@Deprecated public Subfield getSubfield(char code)
Deprecated.Returns the firstSubfield
with the suppliedchar
code.- Parameters:
code
- A Subfield code- Returns:
- A Subfield instance or null
-
getFirstSubfield
public Optional<Subfield> getFirstSubfield(char code)
Returns the firstSubfield
with the suppliedchar
code.- Parameters:
code
- A Subfield code- Returns:
- An
Optional<Subfield>
of the first subfield with the suppliedchar
code
-
getSubfields
public Stream<Subfield> getSubfields(char code)
- Parameters:
code
- A Subfield code- Returns:
- A Stream of Subfield
-
hasSubfield
public boolean hasSubfield(char code)
Returns true if there is a subfield with the given identifier.
- Parameters:
code
- the data element identifier- Returns:
- true if the data element exists, false if not
-
setTag
public void setTag(String tag)
Registers the tag.
- Overrides:
setTag
in classVariableField
- Parameters:
tag
- the tag name- Throws:
IllegalTagException
- when the tag is not a valid data field identifier
-
setIndicator1
public void setIndicator1(char ind1)
Registers the first indicator value.
- Parameters:
ind1
- the first indicator- Throws:
IllegalIndicatorException
- when the indicator value is invalid
-
setIndicator2
public void setIndicator2(char ind2)
Registers the second indicator value.
- Parameters:
ind2
- the second indicator- Throws:
IllegalIndicatorException
- when the indicator value is invalid
-
getIndicator1
public char getIndicator1()
Returns the first indicator.
- Returns:
char
- the first indicator
-
getIndicator2
public char getIndicator2()
Returns the second indicator.
- Returns:
char
- the second indicator
-
getSubfieldList
@Deprecated public List<Subfield> getSubfieldList()
Deprecated.Use {getSubfields()
Returns the collection of data elements.
-
setSubfieldList
@Deprecated public void setSubfieldList(List<Subfield> subfields)
Deprecated.Use {setSubfields(List)
Sets the collection of data elements.
A collection of data elements is a
List
object with null or moreSubfield
objects.Note: this method replaces the current
List
of subfields with the subfields in the newList
.- Parameters:
newList
- the new data element collection
-
setSubfields
public void setSubfields(List<Subfield> subfields)
Sets the collection of data elements.
A collection of data elements is a
List
object with null or moreSubfield
objects.Note: this method replaces the current
List
of subfields with the subfields in the newList
.- Parameters:
newList
- the new data element collection
-
marshal
public String marshal()
Returns a
String
representation for a data field following the structure of a MARC data field.- Returns:
String
- the data field
-
getLength
public int getLength()
Returns the length of the serialized form of the current data field.
- Returns:
int
- the data field length
-
clone
@Deprecated public Object clone()
Deprecated.- Specified by:
clone
in classVariableField
-
equals
public boolean equals(Object obj)
- Specified by:
equals
in classVariableField
-
hashCode
public int hashCode()
- Specified by:
hashCode
in classVariableField
-
-