Class Record

  • All Implemented Interfaces:
    Serializable, Cloneable

    public class Record
    extends Object
    implements Serializable, Cloneable
    Record defines behaviour for a record.

    The structure of a record according to the MARC standard is as follows:

     LEADER  DIRECTORY  FT  CONTROL_NUMBER_FIELD  FT  CONTROL_FIELD_1  FT   ...   CONTROL_FIELD_n  FT  DATA_FIELD_1  FT   ...   DATA_FIELD_n  FT  RT
     

    This structure is returned by the marshal() method.

    Note: the control number field (tag 001) is an instance of a ControlField. The method add(ControlField field) throws an IllegalAddException when more than one control number field is supplied.

    Author:
    Bas Peters
    See Also:
    Serialized Form
    • Constructor Detail

      • Record

        public Record()
        Default constructor.
      • Record

        public Record​(Leader leader)
        Creates a new instance for a record and sets a leader.
        Parameters:
        leader - the Leader object
      • Record

        public Record​(Record other)
        Copy constructor Copy id attributes of contained ControlField and DataField instances, so if you don't want has the same, use copy(Record).
        Parameters:
        other - Another instance of Record, where to copy all the values
    • Method Detail

      • newRecordWithEmptyLeader

        public static Record newRecordWithEmptyLeader()
        Builds a instance of Record with an empty Leader
      • copy

        public static Record copy​(Record original)
        Creates a copy of the original instance without copy the id attributes of its ControlField and DataFields instances.
        Parameters:
        original - Instance to copy.
        Returns:
        new copy of original instance.
      • getLeader

        public Leader getLeader()
        Returns the leader.
        Returns:
        Leader - the leader
      • add

        public void add​(Leader leader)
        Registers the leader.
        Parameters:
        leader - the Leader object
      • add

        public void add​(ControlField field)
        Adds a new ControlField instance to the collection of variable fields.

        Checks if the variable field is a control number field (tag 001). If the field is a control number field an IllegalAddException is thrown when there is already a control number field in the field collection.

        Parameters:
        field - the control field
        Throws:
        IllegalAddException - when there is already a control number field on the field map
      • add

        public void add​(DataField field)
        Adds a new DataField instance to the collection of variable fields.
        Parameters:
        field - the data field
      • getControlNumberField

        public ControlField getControlNumberField()
        Returns the control number field (tag 001).
        Returns:
        ControlField - the control number field
      • getControlNumber

        public String getControlNumber()
        Returns the control number (contents for tag 001).
        Returns:
        String - the control number value
      • getControlField

        public ControlField getControlField​(String tag)
        Returns the control field for the given tag.
        Parameters:
        tag - the tag name
        Returns:
        ControlField - the control field object
      • hasVariableField

        public boolean hasVariableField​(String tag)
        Returns true if there is a variable field with the given tag.
        Parameters:
        tag - the tag name
        Returns:
        true if the variable field exists, false if not
      • getFirstDataField

        public DataField getFirstDataField​(String tag)
        Returns the first data field for the given tag.
        Parameters:
        tag - Tag name
        Returns:
        DataField
      • hasControlNumberField

        public boolean hasControlNumberField()

        Returns true if the collection of variable fields contains a control number field.

        Returns:
        boolean - true if there is a control number field, false if there is no control number field
      • getControlFieldList

        @Deprecated
        public List<ControlField> getControlFieldList()
        Deprecated.
        Returns the collection of control fields.

        The collection of control fields contains:

        • the control number field
        • control fields

        Returns:
        List - the control field collection
        See Also:
        ControlField
      • getControlFields

        public List<ControlField> getControlFields()
        Returns the collection of control fields.

        The collection of control fields contains:

        • the control number field
        • control fields

        Returns:
        List - the control field collection
        See Also:
        ControlField
      • setControlFieldList

        @Deprecated
        public void setControlFieldList​(List<ControlField> newList)
        Deprecated.
        Use #setControlFields(List)
        Sets the collection of control fields.

        A collection of control fields is a List object with null or more ControlField objects.

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

        Parameters:
        newList - the new control field collection
      • setControlFields

        public void setControlFields​(Collection<ControlField> newControlFields)
        Sets the collection of control fields.

        A collection of control fields is a List object with null or more ControlField objects.

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

        Parameters:
        newControlFields - the new control field collection
        Throws:
        IllegalAddException - if newList contains an object that isn't an instance of ControlField
      • getDataFields

        public List<DataField> getDataFields()
        Returns the collection of data fields.
        Returns:
        List - the data field collection
        See Also:
        DataField
      • setDataFieldList

        @Deprecated
        public void setDataFieldList​(List<DataField> newList)
        Deprecated.
        Use #setDataFields(List)
        Sets the collection of data fields.

        A collection of data fields is a List object with null or more DataField objects.

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

        Parameters:
        newList - the new data field collection
      • setDataFields

        public void setDataFields​(Collection<DataField> newDataFields)
        Sets the collection of data fields.

        A collection of data fields is a List object with null or more DataField objects.

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

        Parameters:
        newDataFields - the new data field collection
      • getVariableFields

        public List<VariableField> getVariableFields()
        Returns the collection of variable fields.

        The collection of variable fields contains:

        • the control number field
        • control fields
        • data fields

        Returns:
        List - the variable field collection
        See Also:
        ControlField, DataField
      • setVariableFieldList

        @Deprecated
        public void setVariableFieldList​(List<VariableField> newList)
        Deprecated.
        Use #setVariableFields(List)
        Sets the collection of variable fields.

        A collection of variable fields is a List object with null or more ControlField or DataField objects.

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

        Parameters:
        newList - the new variable field collection
      • setVariableFields

        public void setVariableFields​(Collection<VariableField> newVariableFields)
        Sets the collection of variable fields.

        A collection of variable fields is a List object with null or more ControlField or DataField objects.

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

        Parameters:
        newVariableFields - the new variable field collection
      • getVariableFieldsStream

        public Stream<VariableField> getVariableFieldsStream()
        Returns a stream of the variable fields of this record
      • getVariableFieldsStreamPrefixedBy

        public Stream<? extends VariableField> getVariableFieldsStreamPrefixedBy​(String tagPrefix)
        Returns a stream of the variable fields of this record, that have the indicated tag or are prefixed by a tag value
        Parameters:
        tagPrefix - Complete Fieldtag (ie, 010, 200, 536, etc) or the fieldtag prefix (1 -> returns the datafields 1XX)
        Returns:
        A stream of VariableFields that matchs the tag. If the tag is empty, then returns an empty stream.
      • getVariableFieldsStream

        public Stream<? extends VariableField> getVariableFieldsStream​(String tag)
        Returns a stream of the variable fields of this record, that have the indicated tag
        Parameters:
        tag - Complete Fieldtag (ie, 010, 200, 536, etc)
        Returns:
        A stream of VariableFields that matchs the tag. If the tag is empty, then returns an empty stream.
      • getFirstVariableField

        public VariableField getFirstVariableField​(String tag)
        Returns the first Variable Field for the given tag.
        Parameters:
        tag - Tag name
        Returns:
        VariableField or null
      • getControlFieldsStream

        public Stream<ControlField> getControlFieldsStream()
        Returns a stream of the control fields of this record
      • getControlFieldsStreamPrefixedBy

        public Stream<ControlField> getControlFieldsStreamPrefixedBy​(String tagPrefix)
        Returns a stream of the control fields of this record, that have the indicated tag or are prefixed by a tag value
        Parameters:
        tagPrefix - Complete Fieldtag (ie, 010, 001, etc) or the fieldtag prefix (01 -> returns the controlfields 01X)
        Returns:
        A stream of ControlField that matchs the tag. If the tag is empty, then returns all the control fields
      • getControlFieldsStream

        public Stream<ControlField> getControlFieldsStream​(String tag)
        Returns a stream of the control fields of this record, that have the indicated tag
        Parameters:
        tag - Complete Fieldtag (ie, 010, 001, etc)
        Returns:
        A stream of ControlField that matchs the tag. If the tag is empty, then returns all the control fields
      • getDataFieldsStream

        public Stream<DataField> getDataFieldsStream()
        Returns a stream of the data fields of this record
      • getDataFieldsStreamPrefixedBy

        public Stream<DataField> getDataFieldsStreamPrefixedBy​(String tagPrefix)
        Returns a stream of the data fields of this record, that have the indicated tag or are prefixed by a tag value
        Parameters:
        tagPrefix - Complete Fieldtag (ie, 100, 200, 345, etc) or the fieldtag prefix (1 -> returns the datafields 1XX)
        Returns:
        A stream of ControlField that matchs the tag. If the tag is empty, then returns all data fields
      • getDataFieldsStream

        public Stream<DataField> getDataFieldsStream​(String tag)
        Returns a stream of the data fields of this record, that have the indicated tag
        Parameters:
        tag - Complete Fieldtag (ie, 100, 200, 345, etc)
        Returns:
        A stream of ControlField that matchs the tag. If the tag is empty, then returns all data fields
      • find

        public Stream<VariableField> find​(Pattern pattern)
        Returns a List of VariableField objects that have a data element that matches the given regular expression.

        See Pattern for more information about Java regular expressions.

        Parameters:
        pattern - An instance of a compiled Pattern to use as matcher
        Returns:
        A stream of VariableFields that matches the pattern
      • find

        public Stream<VariableField> find​(String tag,
                                          Pattern pattern)
        Returns a List of VariableField objects with the given tag that have a data element that matches the given regular expression.

        See Pattern for more information about Java regular expressions.

        Parameters:
        tag - A field tag value
        pattern - An instance of a compiled Pattern to use as matcher
        Returns:
        A stream of VariableFields that matches the given tags, and the pattern
      • find

        public Stream<VariableField> find​(Collection<String> tags,
                                          Pattern pattern)
        Returns a List of VariableField objects with the given tags that have a data element that matches the given regular expression.

        See Pattern for more information about Java regular expressions.

        Parameters:
        tags - A collection of tag values
        pattern - An instance of a compiled Pattern to use as matcher
        Returns:
        A stream of VariableFields that matches any tag of the given tags, and the pattern
      • marshal

        public String marshal()
        Returns a String representation for a record following the structure of a MARC record (tape format).

        Variable fields are sorted by tag name.

        Returns:
        String - the MARC record
        Throws:
        MarcException - if the record contains no leader or no control number field
      • marshal

        public String marshal​(String encoding)
        Returns a String representation for a record following the structure of a MARC record (tape format).

        Variable fields are sorted by tag name.

        Parameters:
        encoding - charset encoding used to calculate the fields length.
        Returns:
        String - the MARC record
        Throws:
        MarcException - if the record contains no leader or no control number field.
        MarcException - if the encoding is invalid.