public class DefaultRecordType extends Object implements RecordType, Serializable
RecordType
is identified by a type name and contains an
arbitrary amount of members as (name, type) pairs.
A RecordType
may therefore contain another RecordType
as a member.
RecordType
instances can be though as equivalent to instances of the Java Class
class.
The set of members in a RecordType
can be though as equivalent to the set of fields in a class.
DefaultRecordType
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<?>> members = new LinkedHashMap<>(); members.put("city", String .class); members.put("latitude", Double .class); members.put("longitude", Double .class); members.put("population", Integer.class); RecordType record = schema.createRecordType("MyRecordType", members);
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.
DefaultRecordSchema
is currently not serializable,
so users wanting serialization may need to provide their own schema.DefaultRecord
,
DefaultRecordSchema
,
DefaultMemberName
,
Serialized FormDefined in the sis-utility
module
Constructor and Description |
---|
DefaultRecordType(RecordType other)
Creates a new record with the same names and members than the given one.
|
DefaultRecordType(TypeName typeName,
RecordSchema container,
Map<? extends MemberName,? extends Type> members)
Creates a new record in the given schema.
|
Modifier and Type | Method and Description |
---|---|
static DefaultRecordType |
castOrCopy(RecordType other)
Returns a SIS implementation with the name and members of the given arbitrary implementation.
|
boolean |
equals(Object other)
Compares the given object with this
RecordType for equality. |
RecordSchema |
getContainer()
Returns the schema that contains this record type.
|
Set<MemberName> |
getMembers()
Returns the set of attribute names defined in this
RecordType 's dictionary. |
Map<MemberName,Type> |
getMemberTypes()
Returns the dictionary of all (name, type) pairs in this record type.
|
TypeName |
getTypeName()
Returns the name that identifies this record type.
|
int |
hashCode()
Returns a hash code value for this
RecordType . |
boolean |
isInstance(Record record)
Determines if the given record is compatible with this record type.
|
TypeName |
locate(MemberName memberName)
Returns the type associated to the given attribute name, or
null if none. |
String |
toString()
Returns a string representation of this object.
|
public DefaultRecordType(RecordType other)
other
- the RecordType
to copy.public DefaultRecordType(TypeName typeName, RecordSchema container, Map<? extends MemberName,? extends Type> members)
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.
typeName
- the name that identifies this record type.container
- the schema that contains this record type.members
- the name and type of the members to be included in this record type.DefaultRecordSchema.createRecordType(CharSequence, Map)
public static DefaultRecordType castOrCopy(RecordType other)
null
, then this method returns null
.DefaultRecordType
,
then it is returned unchanged.DefaultRecordType
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.other
- the object to get as a SIS implementation, or null
if none.null
if the argument was null
.public TypeName getTypeName()
RecordType
is 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()
RecordType
as equivalent to a Class
instance,
then this method can be think as the equivalent of the Java Class.getName()
method.
getTypeName
in interface RecordType
getTypeName
in interface Type
public RecordSchema getContainer()
getContainer
in interface RecordType
public Map<MemberName,Type> getMemberTypes()
RecordType
as equivalent to a Class
instance, then
this method can be though as the related to the Java Class.getFields()
method.
getMemberTypes
in interface RecordType
public Set<MemberName> getMembers()
RecordType
's dictionary.
This method is functionally equivalent to:
getMemberTypes().keySet();
getMembers
in interface RecordType
public TypeName locate(MemberName memberName)
null
if none.
This method is functionally equivalent to (omitting the check for null value):
getMemberTypes().get(memberName).getTypeName();
RecordType
as equivalent to a Class
instance, then
this method can be though as related to the Java Class.getField(String)
method.
locate
in interface RecordType
memberName
- the attribute name for which to get the associated type name.null
if none.public boolean isInstance(Record record)
true
if the given record
argument is non-null and the following condition holds:
Set<MemberName> attributeNames = record.getAttributes().keySet(); boolean isInstance = getMembers().containsAll(attributeNames);
record.getRecordType() == this
in order to allow record
"sub-types" to define additional fields, in a way similar to Java sub-classing.isInstance
in interface RecordType
record
- the record to test for compatibility.true
if the given record is compatible with this RecordType
.public boolean equals(Object other)
RecordType
for equality.public int hashCode()
RecordType
.Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.