Class Record
- java.lang.Object
-
- org.marc4j.marc.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 methodadd(ControlField field)
throws anIllegalAddException
when more than one control number field is supplied.- Author:
- Bas Peters
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Record()
Default constructor.Record(Leader leader)
Creates a new instance for a record and sets a leader.Record(Record other)
Copy constructor Copy id attributes of contained ControlField and DataField instances, so if you don't want has the same, usecopy(Record)
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(ControlField field)
Adds a newControlField
instance to the collection of variable fields.void
add(DataField field)
Adds a newDataField
instance to the collection of variable fields.void
add(Leader leader)
Registers the leader.Object
clone()
Deprecated.Use copy constructorRecord(org.marc4j.marc.Record)
static Record
copy(Record original)
Creates a copy of the original instance without copy the id attributes of its ControlField and DataFields instances.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.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.Stream<VariableField>
find(Pattern pattern)
Returns a List of VariableField objects that have a data element that matches the given regular expression.ControlField
getControlField(String tag)
Returns the control field for the given tag.List<ControlField>
getControlFieldList()
Deprecated.List<ControlField>
getControlFields()
Returns the collection of control fields.Stream<ControlField>
getControlFieldsStream()
Returns a stream of the control fields of this recordStream<ControlField>
getControlFieldsStream(String tag)
Returns a stream of the control fields of this record, that have the indicated tagStream<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 valueString
getControlNumber()
Returns the control number (contents for tag 001).ControlField
getControlNumberField()
Returns the control number field (tag 001).DataField
getDataField(String tag)
Deprecated.List<DataField>
getDataFieldList()
Deprecated.UsegetDataFields()
List<DataField>
getDataFields()
Returns the collection of data fields.Stream<DataField>
getDataFieldsStream()
Returns a stream of the data fields of this recordStream<DataField>
getDataFieldsStream(String tag)
Returns a stream of the data fields of this record, that have the indicated tagStream<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 valueDataField
getFirstDataField(String tag)
Returns the first data field for the given tag.VariableField
getFirstVariableField(String tag)
Returns the first Variable Field for the given tag.Leader
getLeader()
Returns the leader.List<VariableField>
getVariableFieldList()
Deprecated.List<VariableField>
getVariableFields()
Returns the collection of variable fields.Stream<VariableField>
getVariableFieldsStream()
Returns a stream of the variable fields of this recordStream<? extends VariableField>
getVariableFieldsStream(String tag)
Returns a stream of the variable fields of this record, that have the indicated tagStream<? 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 valueboolean
hasControlNumberField()
Returns true if the collection of variable fields contains a control number field.boolean
hasVariableField(String tag)
Returns true if there is a variable field with the given tag.String
marshal()
Returns aString
representation for a record following the structure of a MARC record (tape format).String
marshal(String encoding)
Returns aString
representation for a record following the structure of a MARC record (tape format).static Record
newRecordWithEmptyLeader()
Builds a instance of Record with an empty Leadervoid
setControlFieldList(List<ControlField> newList)
Deprecated.Use#setControlFields(List)
void
setControlFields(Collection<ControlField> newControlFields)
Sets the collection of control fields.void
setDataFieldList(List<DataField> newList)
Deprecated.Use#setDataFields(List)
void
setDataFields(Collection<DataField> newDataFields)
Sets the collection of data fields.void
setVariableFieldList(List<VariableField> newList)
Deprecated.Use#setVariableFields(List)
void
setVariableFields(Collection<VariableField> newVariableFields)
Sets the collection of variable fields.String
toString()
-
-
-
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
- theLeader
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, usecopy(Record)
.- Parameters:
other
- Another instance ofRecord
, 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.
-
add
public void add(ControlField field)
Adds a newControlField
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 newDataField
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
-
getDataField
@Deprecated public DataField getDataField(String tag)
Deprecated.Returns the first data field for the given tag.- Parameters:
tag
- Tag name- Returns:
- DataField
-
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 moreControlField
objects.Note: this method replaces the current
List
of control fields with the control fields in the newList
.- 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 moreControlField
objects.Note: this method replaces the current
List
of control fields with the control fields in the newList
.- Parameters:
newControlFields
- the new control field collection- Throws:
IllegalAddException
- if newList contains an object that isn't an instance of ControlField
-
getDataFieldList
@Deprecated public List<DataField> getDataFieldList()
Deprecated.UsegetDataFields()
Returns the collection of data fields.
-
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 moreDataField
objects.Note: this method replaces the current
List
of data fields with the data fields in the newList
.- 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 moreDataField
objects.Note: this method replaces the current
List
of data fields with the data fields in the newList
.- Parameters:
newDataFields
- the new data field collection
-
getVariableFieldList
@Deprecated public List<VariableField> getVariableFieldList()
Deprecated.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
-
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 moreControlField
orDataField
objects.Note: this method replaces the current
List
of variable fields with the variable fields in the newList
.- 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 moreControlField
orDataField
objects.Note: this method replaces the current
List
of variable fields with the variable fields in the newList
.- 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 valuepattern
- 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 valuespattern
- 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 aString
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 aString
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.
-
clone
@Deprecated public Object clone()
Deprecated.Use copy constructorRecord(org.marc4j.marc.Record)
- Overrides:
clone
in classObject
- See Also:
Object.clone()
-
-