Class DefaultRecordType

Object
DefaultRecordType
All Implemented Interfaces:
Serializable, Record­Type, Type

public class DefaultRecordType extends Object implements RecordType, Serializable
An immutable definition of the type of a record. A Record­Type is identified by a type name and contains an arbitrary number of members (fields) as (name, type) pairs. A Record­Type may therefore contain another Record­Type as a field.
Comparison with Java reflection: Record­Type instances can be though as equivalent to instances of the Java Class class. The set of fields in a Record­Type can be though as equivalent to the set of fields in a class.
Possible future change: This class is derived from ISO 19103:2005. The record attributes and methods have been modified in ISO 19103:2015, then all classes related to records have been fully removed in ISO 19103:2024. The implication for Apache SIS has not yet been determined. This class may be replaced by a simple Feature­Type.

Immutability and thread safety

This class is immutable and thus inherently thread-safe if the Type­Name, the Record­Schema and all (Member­Name, 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 Record­Type state.

Serialization

This class is serializable if all elements given to the constructor are also serializable.
Since:
0.3
See Also:
  • Field Details

    • SINGLE_STRING

      public static final DefaultRecordType SINGLE_STRING
      A type of record instances for holding a single String value.
      Since:
      1.6
    • SINGLE_REAL

      public static final DefaultRecordType SINGLE_REAL
      A type of record instances for holding a single Double value.
      Since:
      1.6
  • Constructor Details

    • DefaultRecordType

      public DefaultRecordType(RecordType other)
      Creates a new record with the same names and fields than the given one.
      Parameters:
      other - the Record­Type to copy.
    • DefaultRecordType

      public DefaultRecordType(TypeName typeName, Map<? extends MemberName, ? extends Type> fields)
      Creates a new record type.
      Parameters:
      type­Name - the name that identifies this record type.
      fields - the name and type of the fields to be included in this record type.
      Since:
      1.5
  • Method Details

    • castOrCopy

      public static DefaultRecordType castOrCopy(RecordType other)
      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 returns null.
      • Otherwise if the given object is already an instance of Default­Record­Type, then it is returned unchanged.
      • Otherwise a new Default­Record­Type instance 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, or null if none.
      Returns:
      a SIS implementation containing the fields of the given object (may be the given object itself), or null if the argument was null.
    • getTypeName

      public TypeName getTypeName()
      Returns the name that identifies this record type.
      Comparison with Java reflection: If we think about this Record­Type as equivalent to a Class instance, then this method can be think as the equivalent of the Java Class​.get­Name() method.
      Specified by:
      get­Type­Name in interface Record­Type
      Specified by:
      get­Type­Name in interface Type
      Returns:
      the name that identifies this record type.
    • getContainer

      @Deprecated(since="1.0") public RecordSchema getContainer()
      Deprecated.
      The Record­Schema interface has been removed in the 2015 revision of ISO 19103 standard.
      Returns the schema that contains this record type.
      Specified by:
      get­Container in interface Record­Type
      Returns:
      the schema that contains this record type, or null if none.
    • getMemberTypes

      @Deprecated public Map<MemberName, Type> getMemberTypes()
      Deprecated.
      Renamed get­Field­Types() 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 this Record­Type as equivalent to a Class instance, then this method can be though as the related to the Java Class​.get­Fields() method.
      Specified by:
      get­Member­Types in interface Record­Type
      Returns:
      the dictionary of (name, type) pairs, or an empty map if none.
      See Also:
    • getFieldTypes

      public Map<MemberName, Type> 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 this Record­Type as equivalent to a Class instance, then this method can be though as the related to the Java Class​.get­Fields() method.
      Returns:
      the dictionary of (name, type) pairs, or an empty map if none.
      Since:
      1.1
    • getMembers

      public Set<MemberName> getMembers()
      Returns the set of attribute names defined in this Record­Type's dictionary. This method is functionally equivalent to the following code, but slightly more efficient:
      getFieldTypes().keySet();
      
      Specified by:
      get­Members in interface Record­Type
      Returns:
      the set of field names, or an empty set if none.
    • locate

      public TypeName locate(MemberName fieldName)
      Returns the type associated to the given attribute name, or null if 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 this Record­Type as equivalent to a Class instance, then this method can be though as related to the Java Class​.get­Field(String) method.
      Specified by:
      locate in interface Record­Type
      Parameters:
      field­Name - the attribute name for which to get the associated type name.
      Returns:
      the associated type name, or null if none.
      See Also:
    • isInstance

      public boolean isInstance(Record record)
      Determines if the given record is compatible with this record type. This method returns true if the given record argument is non-null and the following condition is true:
      Set<MemberName> attributeNames = record.getAttributes().keySet();
      boolean isInstance = getMembers().containsAll(attributeNames);
      

      Implementation note

      We do not require that record​.get­Record­Type() == this in order to allow record "sub-types" to define additional fields, in a way similar to Java sub-classing.
      Specified by:
      is­Instance in interface Record­Type
      Parameters:
      record - the record to test for compatibility with this type, or null.
      Returns:
      true if the given record is non-null and compatible with this record type.
    • equals

      public boolean equals(Object other)
      Compares the given object with this Record­Type for equality.
      Overrides:
      equals in class Object
      Parameters:
      other - the object to compare with this Record­Type.
      Returns:
      true if both objects are equal.
    • hashCode

      public int hashCode()
      Returns a hash code value for this Record­Type.
      Overrides:
      hash­Code in class Object
    • toString

      public String toString()
      Returns a string representation of this object. The string representation is for debugging purpose and may change in any future SIS version.
      Overrides:
      to­String in class Object
      Returns:
      a string representation of this record type.