Package org.apache.sis.util.iso
Class DefaultRecordType
Object
DefaultRecordType
- All Implemented Interfaces:
Serializable,RecordType,Type
An immutable definition of the type of a record.
A
RecordType is identified by a type name and contains an
arbitrary number of members (fields) as (name, type) pairs.
A RecordType may therefore contain another RecordType as a field.
Comparison with Java reflection:
RecordType instances can be though as equivalent to instances of the Java Class class.
The set of fields in a RecordType can be though as equivalent to the set of fields in a class.
Instantiation
The easiest way to createDefaultRecordType instances is to use the
DefaultRecordSchema.createRecordType(CharSequence, Map) method.
Example:
DefaultRecordSchema schema = new DefaultRecordSchema(null, null, "MySchema");
// The same instance can be reused for all records to create in that schema.
Map<CharSequence,Class<?>> fields = new LinkedHashMap<>();
fields.put("city", String .class);
fields.put("latitude", Double .class);
fields.put("longitude", Double .class);
fields.put("population", Integer.class);
RecordType record = schema.createRecordType("MyRecordType", fields);
Immutability and thread safety
This class is immutable and thus inherently thread-safe if theTypeName, the RecordSchema
and all (MemberName, Type) entries in the map given to the constructor are also immutable.
Subclasses shall make sure that any overridden methods remain safe to call from multiple threads and do not change
any public RecordType state.
Serialization
This class is serializable if all elements given to the constructor are also serializable. Note in particular thatDefaultRecordSchema is currently not serializable,
so users wanting serialization may need to provide their own schema.- Since:
- 0.3
- See Also:
Defined in the sis-metadata module
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultRecordType(RecordType other) Creates a new record with the same names and fields than the given one.DefaultRecordType(TypeName typeName, RecordSchema container, Map<? extends MemberName, ? extends Type> fields) Creates a new record in the given schema. -
Method Summary
Modifier and TypeMethodDescriptionstatic DefaultRecordTypecastOrCopy(RecordType other) Returns a SIS implementation with the name and fields of the given arbitrary implementation.booleanCompares the given object with thisRecordTypefor equality.Deprecated.Returns the dictionary of all (name, type) pairs in this record type.Returns the set of attribute names defined in thisRecordType's dictionary.Deprecated.RenamedgetFieldTypes()for consistency with the 2015 revision of ISO 19103 standard.Returns the name that identifies this record type.intReturns a hash code value for thisRecordType.booleanisInstance(Record record) Determines if the given record is compatible with this record type.locate(MemberName fieldName) Returns the type associated to the given attribute name, ornullif none.Returns a string representation of this object.
-
Constructor Details
-
DefaultRecordType
Creates a new record with the same names and fields than the given one.- Parameters:
other- theRecordTypeto copy.
-
DefaultRecordType
public DefaultRecordType(TypeName typeName, RecordSchema container, Map<? extends MemberName, ? extends Type> fields) Creates a new record in the given schema. It is caller responsibility to add the newRecordTypein the container description map, if desired.This constructor is provided mostly for developers who want to create
DefaultRecordTypeinstances in their ownRecordSchemaimplementation. Otherwise if the default record schema implementation is sufficient, theDefaultRecordSchema.createRecordType(CharSequence, Map)method provides an easier alternative.- Parameters:
typeName- the name that identifies this record type.container- the schema that contains this record type.fields- the name and type of the fields to be included in this record type.- See Also:
-
-
Method Details
-
castOrCopy
Returns a SIS implementation with the name and fields 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
DefaultRecordType, then it is returned unchanged. - Otherwise a new
DefaultRecordTypeinstance is created using the copy constructor and returned. Note that this is a shallow copy operation, since the fields contained in the given object are not recursively copied.
- Parameters:
other- the object to get as a SIS implementation, ornullif none.- Returns:
- a SIS implementation containing the fields of the given object
(may be the given object itself), or
nullif the argument wasnull.
- If the given object is
-
getTypeName
Returns the name that identifies this record type. If thisRecordTypeis contained in a record schema, then the record type name shall be valid in the name space of the record schema:NameSpace namespace = getContainer().getSchemaName().scope()
Comparison with Java reflection: If we think about thisRecordTypeas equivalent to aClassinstance, then this method can be think as the equivalent of the JavaClass.getName()method.- Specified by:
getTypeNamein interfaceRecordType- Specified by:
getTypeNamein interfaceType- Returns:
- the name that identifies this record type.
-
getContainer
Deprecated.TheRecordSchemainterface has been removed in the 2015 revision of ISO 19103 standard.Returns the schema that contains this record type.- Specified by:
getContainerin interfaceRecordType- Returns:
- the schema that contains this record type.
-
getMemberTypes
Deprecated.RenamedgetFieldTypes()for consistency with the 2015 revision of ISO 19103 standard.Returns the dictionary of all (name, type) pairs in this record type. The returned map is unmodifiable.Comparison with Java reflection: If we think about thisRecordTypeas equivalent to aClassinstance, then this method can be though as the related to the JavaClass.getFields()method.- Specified by:
getMemberTypesin interfaceRecordType- Returns:
- the dictionary of (name, type) pairs, or an empty map if none.
-
getFieldTypes
Returns the dictionary of all (name, type) pairs in this record type. The returned map is unmodifiable.Comparison with Java reflection: If we think about thisRecordTypeas equivalent to aClassinstance, then this method can be though as the related to the JavaClass.getFields()method.- Returns:
- the dictionary of (name, type) pairs, or an empty map if none.
- Since:
- 1.1
-
getMembers
Returns the set of attribute names defined in thisRecordType's dictionary. This method is functionally equivalent to the following code, but slightly more efficient:getFieldTypes().keySet();
- Specified by:
getMembersin interfaceRecordType- Returns:
- the set of field names, or an empty set if none.
-
locate
Returns the type associated to the given attribute name, ornullif none. This method is functionally equivalent to (omitting the check for null value):getFieldTypes().get(name).getTypeName();
Comparison with Java reflection: If we think about thisRecordTypeas equivalent to aClassinstance, then this method can be though as related to the JavaClass.getField(String)method.- Specified by:
locatein interfaceRecordType- Parameters:
fieldName- the attribute name for which to get the associated type name.- Returns:
- the associated type name, or
nullif none.
-
isInstance
Determines if the given record is compatible with this record type. This method returnstrueif the givenrecordargument is non-null and the following condition holds:Set<MemberName> attributeNames = record.getAttributes().keySet(); boolean isInstance = getMembers().containsAll(attributeNames);
Implementation note: We do not require thatrecord.getRecordType() == thisin order to allow record "sub-types" to define additional fields, in a way similar to Java sub-classing.- Specified by:
isInstancein interfaceRecordType- Parameters:
record- the record to test for compatibility.- Returns:
trueif the given record is compatible with thisRecordType.
-
equals
Compares the given object with thisRecordTypefor equality. -
hashCode
public int hashCode()Returns a hash code value for thisRecordType. -
toString
Returns a string representation of this object. The string representation is for debugging purpose and may change in any future SIS version.
-
RecordSchemainterface has been removed in the 2015 revision of ISO 19103 standard.