Class 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
    • Constructor Detail

      • DataField

        public DataField()
        Default constructor.
      • DataField

        public DataField​(String tag)
        Creates a new DataField instance and registers the tag name.
        Parameters:
        tag - The tag name
      • DataField

        public DataField​(String tag,
                         char ind1,
                         char ind2)
        Creates a new DataField and sets the tag name and the first and second indicator.
        Parameters:
        tag - The tag name
        ind1 - The first indicator
        ind2 - The second indicator
      • DataField

        public DataField​(String tag,
                         char ind1,
                         char ind2,
                         Long id)
        Creates a new DataField and sets the tag name and the first and second indicator, and the id
        Parameters:
        tag - The tag name
        ind1 - The first indicator
        ind2 - The second indicator
        id - The id for the DataField
      • DataField

        public DataField​(DataField other)
        Copy constructor Copy id attribute, so if you don't want has the same, use copy(DataField).
        Parameters:
        other - Another instance of DataField, 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)
        Returns true if a match is found for the supplied regular expression pattern; else, false.
        Specified by:
        find in class VariableField
        Parameters:
        pattern - An instance of a compiled Pattern to use as matcher
      • addSubfield

        public void addSubfield​(int index,
                                Subfield subfield)
        Adds a new Subfield 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).
        Parameters:
        index - The subfield's position within the list
        subfield - The Subfield of a DataField
      • removeSubfield

        public void removeSubfield​(Subfield subfield)
        Removes a Subfield from the field.
        Parameters:
        subfield - The subfield to remove from the field.
      • getFirstSubfield

        public Optional<Subfield> getFirstSubfield​(char code)
        Returns the first Subfield with the supplied char code.
        Parameters:
        code - A Subfield code
        Returns:
        An Optional<Subfield> of the first subfield with the supplied char code
      • getSubfields

        public Stream<Subfield> getSubfields​(char code)
        Returns a Stream of Subfields with the supplied 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
      • 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
      • getSubfields

        public List<Subfield> getSubfields()
        Returns the collection of Subfields
        Returns:
        List the Subfield element collection
        See Also:
        Subfield
      • setSubfieldList

        @Deprecated
        public void setSubfieldList​(List<Subfield> subfields)
        Deprecated.

        Sets the collection of data elements.

        A collection of data elements is a List object with null or more Subfield objects.

        Note: this method replaces the current List of subfields with the subfields in the new List.

        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 more Subfield objects.

        Note: this method replaces the current List of subfields with the subfields in the new List.

        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