Class DefaultRecordType

java.lang.Object
org.apache.sis.util.iso.RecordDefinition
org.apache.sis.util.iso.DefaultRecordType
All Implemented Interfaces:
Serializable, org.opengis.util.RecordType, org.opengis.util.Type

public class DefaultRecordType extends RecordDefinition implements org.opengis.util.RecordType, Serializable
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 create DefaultRecordType instances is to use the DefaultRecordSchema.createRecordType(CharSequence, Map) method. Example:

Immutability and thread safety

This class is immutable and thus inherently thread-safe if the TypeName, 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 that DefaultRecordSchema is currently not serializable, so users wanting serialization may need to provide their own schema.
Since:
0.3
Version:
1.3
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.sis.util.iso.RecordDefinition

    RecordDefinition.Adapter
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final org.opengis.util.RecordSchema
    The schema that contains this record type.
    private org.opengis.util.Type[]
    The type of each fields.
    private static final long
    For cross-version compatibility.
    private final org.opengis.util.TypeName
    The name that identifies this record type.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Constructs an initially empty type describing one field per line.
     
    DefaultRecordType(org.opengis.util.RecordType other)
    Creates a new record with the same names and fields than the given one.
    (package private)
    DefaultRecordType(org.opengis.util.TypeName typeName, org.opengis.util.RecordSchema container, Map<? extends CharSequence,? extends org.opengis.util.Type> fields, DefaultNameFactory nameFactory)
    Creates a new record from field names specified as character sequence.
     
    DefaultRecordType(org.opengis.util.TypeName typeName, org.opengis.util.RecordSchema container, Map<? extends org.opengis.util.MemberName,? extends org.opengis.util.Type> fields)
    Creates a new record in the given schema.
  • Method Summary

    Modifier and Type
    Method
    Description
    castOrCopy(org.opengis.util.RecordType other)
    Returns a SIS implementation with the name and fields of the given arbitrary implementation.
    boolean
    equals(Object other)
    Compares the given object with this RecordType for equality.
    org.opengis.util.RecordSchema
    Deprecated.
    The RecordSchema interface has been removed in the 2015 revision of ISO 19103 standard.
    Map<org.opengis.util.MemberName,org.opengis.util.Type>
    Returns the dictionary of all (name, type) pairs in this record type.
    Set<org.opengis.util.MemberName>
    Returns the set of attribute names defined in this RecordType's dictionary.
    Map<org.opengis.util.MemberName,org.opengis.util.Type>
    Deprecated.
    Renamed getFieldTypes() for consistency with the 2015 revision of ISO 19103 standard.
    (package private) final org.opengis.util.RecordType
    Returns this since RecordDefinition is the definition of this record type.
    (package private) final org.opengis.util.Type
    getType(int index)
    Returns the type at the given index.
    org.opengis.util.TypeName
    Returns the name that identifies this record type.
    private String
    Returns the record type value as a string.
    int
    Returns a hash code value for this RecordType.
    boolean
    isInstance(org.opengis.util.Record record)
    Determines if the given record is compatible with this record type.
    org.opengis.util.TypeName
    locate(org.opengis.util.MemberName fieldName)
    Returns the type associated to the given attribute name, or null if none.
    private void
    Invoked on deserialization for restoring the transient fields.
    private void
    Sets the record type value as a string.
    private void
    Invoked on serialization for writing the field names and their type.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • typeName

      private final org.opengis.util.TypeName typeName
      The name that identifies this record type.
      See Also:
    • container

      private final org.opengis.util.RecordSchema container
      The schema that contains this record type.
      See Also:
    • fieldTypes

      private transient org.opengis.util.Type[] fieldTypes
      The type of each fields.
      See Also:
  • Constructor Details

    • DefaultRecordType

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

      public DefaultRecordType(org.opengis.util.TypeName typeName, org.opengis.util.RecordSchema container, Map<? extends org.opengis.util.MemberName,? extends org.opengis.util.Type> fields)
      Creates a new record in the given schema. It is caller responsibility to add the new RecordType in the container description map, if desired.

      This constructor is provided mostly for developers who want to create DefaultRecordType instances in their own RecordSchema implementation. Otherwise if the default record schema implementation is sufficient, the DefaultRecordSchema.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:
    • DefaultRecordType

      DefaultRecordType(org.opengis.util.TypeName typeName, org.opengis.util.RecordSchema container, Map<? extends CharSequence,? extends org.opengis.util.Type> fields, DefaultNameFactory nameFactory)
      Creates a new record from field names specified as character sequence. This constructor builds the MemberName instance itself.
      Parameters:
      typeName - the name that identifies this record type.
      container - the schema that contains this record type.
      fields - the name of the fields to be included in this record type.
      nameFactory - the factory to use for instantiating MemberName.
    • DefaultRecordType

      private DefaultRecordType()
      Constructs an initially empty type describing one field per line. See setValue(String) for a description of the supported XML content.
  • Method Details

    • readObject

      private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
      Invoked on deserialization for restoring the transient fields. See writeObject(ObjectOutputStream) for the stream data description.
      Parameters:
      in - the input stream from which to deserialize an object.
      Throws:
      IOException - if an I/O error occurred while reading or if the stream contains invalid data.
      ClassNotFoundException - if the class serialized on the stream is not on the classpath.
    • writeObject

      private void writeObject(ObjectOutputStream out) throws IOException
      Invoked on serialization for writing the field names and their type.
      Parameters:
      out - the output stream where to serialize this object.
      Throws:
      IOException - if an I/O error occurred while writing.
    • castOrCopy

      public static DefaultRecordType castOrCopy(org.opengis.util.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 DefaultRecordType, then it is returned unchanged.
      • Otherwise a new DefaultRecordType 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.
    • getRecordType

      final org.opengis.util.RecordType getRecordType()
      Returns this since RecordDefinition is the definition of this record type.
      Specified by:
      getRecordType in class RecordDefinition
    • getTypeName

      public org.opengis.util.TypeName getTypeName()
      Returns the name that identifies this record type. If this RecordType is contained in a record schema, then the record type name shall be valid in the name space of the record schema:
      Comparison with Java reflection: If we think about this RecordType as equivalent to a Class instance, then this method can be think as the equivalent of the Java Class.getName() method.
      Specified by:
      getTypeName in interface org.opengis.util.RecordType
      Specified by:
      getTypeName in interface org.opengis.util.Type
      Returns:
      the name that identifies this record type.
    • getContainer

      @Deprecated public org.opengis.util.RecordSchema getContainer()
      Deprecated.
      The RecordSchema interface has been removed in the 2015 revision of ISO 19103 standard.
      Returns the schema that contains this record type.
      Specified by:
      getContainer in interface org.opengis.util.RecordType
      Returns:
      the schema that contains this record type.
    • getMemberTypes

      @Deprecated public Map<org.opengis.util.MemberName,org.opengis.util.Type> getMemberTypes()
      Deprecated.
      Renamed getFieldTypes() 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 RecordType as equivalent to a Class instance, then this method can be though as the related to the Java Class.getFields() method.
      Specified by:
      getMemberTypes in interface org.opengis.util.RecordType
      Returns:
      the dictionary of (name, type) pairs, or an empty map if none.
    • getFieldTypes

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

      public Set<org.opengis.util.MemberName> getMembers()
      Returns the set of attribute names defined in this RecordType's dictionary. This method is functionally equivalent to the following code, but slightly more efficient:
      Specified by:
      getMembers in interface org.opengis.util.RecordType
      Returns:
      the set of field names, or an empty set if none.
    • getType

      final org.opengis.util.Type getType(int index)
      Returns the type at the given index.
    • locate

      public org.opengis.util.TypeName locate(org.opengis.util.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):
      Comparison with Java reflection: If we think about this RecordType as equivalent to a Class instance, then this method can be though as related to the Java Class.getField(String) method.
      Specified by:
      locate in interface org.opengis.util.RecordType
      Parameters:
      fieldName - the attribute name for which to get the associated type name.
      Returns:
      the associated type name, or null if none.
    • isInstance

      public boolean isInstance(org.opengis.util.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 holds:
      Implementation note: We do not require that record.getRecordType() == this in order to allow record "sub-types" to define additional fields, in a way similar to Java sub-classing.
      Specified by:
      isInstance in interface org.opengis.util.RecordType
      Parameters:
      record - the record to test for compatibility.
      Returns:
      true if the given record is compatible with this RecordType.
    • equals

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

      public int hashCode()
      Returns a hash code value for this RecordType.
      Overrides:
      hashCode in class Object
    • getValue

      private String getValue()
      Returns the record type value as a string. Current implementation returns the fields with one field per line, but it may change in any future version for adapting to common practice.
    • setValue

      private void setValue(String value)
      Sets the record type value as a string. Current implementation expects one field per line. A record can be anything, but usages that we have seen so far write a character sequence of what seems key-description pairs. Examples:
      See Also: