Package org.apache.sis.util.iso
Class DefaultRecord
- Object
-
- DefaultRecord
-
- All Implemented Interfaces:
Serializable
,Record
public class DefaultRecord extends Object implements Record, Serializable
A list of logically related elements as (name, value) pairs in a dictionary. By definition, all record members have a [1 … 1] multiplicity (for a more flexible construct, see features). Since all members are expected to be assigned a value, the initial values onDefaultRecord
instantiation are unspecified. Some may be null, or some may be zero.Limitations- Multi-threading:
DefaultRecord
instances are not thread-safe. Synchronization, if needed, shall be done externally by the caller. - Serialization: this class is serializable if the associated
RecordType
and all values are also serializable. Note in particular thatDefaultRecordSchema
is currently not serializable, so users wanting serialization may need to define their own schema implementation.
- Since:
- 0.5
- See Also:
DefaultRecordType
,DefaultRecordSchema
, Serialized Form
Defined in the
sis-metadata
module
-
-
Constructor Summary
Constructors Constructor Description DefaultRecord(Record record)
Creates a new record initialized to a shallow copy of the given record.DefaultRecord(RecordType type)
Creates a new record for the given record type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DefaultRecord
castOrCopy(Record other)
Returns a SIS implementation with the name and members of the given arbitrary implementation.boolean
equals(Object object)
Compares this record with the given object for equality.Map<MemberName,Object>
getAttributes()
Returns the dictionary of all (name, value) pairs in this record.RecordType
getRecordType()
Returns the type definition of this record.int
hashCode()
Returns a hash code value for this record.Object
locate(MemberName name)
Returns the value for an attribute of the specified name.void
set(MemberName name, Object value)
Sets the value for the attribute of the specified name.void
setAll(Object... newValues)
Sets all attribute values in this record, in attribute order.String
toString()
Returns a string representation of this record.
-
-
-
Constructor Detail
-
DefaultRecord
public DefaultRecord(RecordType type)
Creates a new record for the given record type. The initial values are unspecified - they may be null or zero. Callers can assign values by a call tosetAll(Object[])
.- Parameters:
type
- the type definition of the new record.
-
DefaultRecord
public DefaultRecord(Record record)
Creates a new record initialized to a shallow copy of the given record. The members contained in the given record are not recursively copied.- Parameters:
record
- the record to copy (can not be null).- Since:
- 0.8
-
-
Method Detail
-
castOrCopy
public static DefaultRecord castOrCopy(Record other)
Returns a SIS implementation with the name and members of the given arbitrary implementation. This method performs the first applicable action in the following choices:- If the given object is
null
, then this method returnsnull
. - Otherwise if the given object is already an instance of
DefaultRecord
, then it is returned unchanged. - Otherwise a new
DefaultRecord
instance is created using the copy constructor and returned. Note that this is a shallow copy operation, since the members contained in the given object are not recursively copied.
- Parameters:
other
- The object to get as a SIS implementation, ornull
if none.- Returns:
- A SIS implementation containing the members of the given object
(may be the given object itself), or
null
if the argument wasnull
. - Since:
- 0.8
- If the given object is
-
getRecordType
public RecordType getRecordType()
Returns the type definition of this record.- Specified by:
getRecordType
in interfaceRecord
- Returns:
- the type definition of this record.
-
getAttributes
public Map<MemberName,Object> getAttributes()
Returns the dictionary of all (name, value) pairs in this record. This method returns a view which will delegate allget
andput
operations to thelocate(MemberName)
andset(MemberName, Object)
methods respectively.- Specified by:
getAttributes
in interfaceRecord
- Returns:
- the dictionary of all (name, value) pairs in this record.
- See Also:
RecordType.getMemberTypes()
-
locate
public Object locate(MemberName name)
Returns the value for an attribute of the specified name.
-
set
public void set(MemberName name, Object value)
Sets the value for the attribute of the specified name.- Specified by:
set
in interfaceRecord
- Parameters:
name
- the name of the attribute to modify.value
- the new value for the attribute.- Throws:
IllegalArgumentException
- if the given name is not a member of this record.ClassCastException
- if the given value is not an instance of the expected type for this record.
-
setAll
public void setAll(Object... newValues)
Sets all attribute values in this record, in attribute order.- Parameters:
newValues
- the attribute values.- Throws:
IllegalArgumentException
- if the given number of values does not match the expected number.ClassCastException
- if a value is not an instance of the expected type for this record.
-
equals
public boolean equals(Object object)
Compares this record with the given object for equality.
-
hashCode
public int hashCode()
Returns a hash code value for this record.
-
-