@Immutable 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.Defined 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<MemberName,Type> memberTypes)
Creates a new record.
|
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
RecordType . |
public DefaultRecordType(RecordType other)
other
- The RecordType
to copy.public DefaultRecordType(TypeName typeName, RecordSchema container, Map<MemberName,Type> memberTypes)
typeName
- The name that identifies this record type.container
- The schema that contains this record type.memberTypes
- The name of the members to be included in this record type.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:
getMemberTypes().get(name);
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);
Note: We do not require that {@code 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–2013 The Apache Software Foundation. All rights reserved.