Package org.apache.uima.cas.impl
Class TypeImpl
- java.lang.Object
-
- org.apache.uima.cas.impl.TypeImpl
-
- Direct Known Subclasses:
TypeImpl_annotBase
,TypeImpl_array
,TypeImpl_list
,TypeImpl_primitive
public class TypeImpl extends java.lang.Object implements Type, java.lang.Comparable<TypeImpl>
The implementation of types in the type system. UIMA Version 3 Instances of this class are not shared by different type systems because they contain a ref to the TypeSystemImpl (needed by FeaturePath and maybe other things) - even for built-ins. - However, the JCas cover class definitions are shared by all type systems for built-in types Feature offsets are set from the (changing) value of nbrOfIntDataFields and nbrOfRefDataFields
-
-
Field Summary
Fields Modifier and Type Field Description private TypeImpl[]
allSuperTypes
All supertypes, in order, starting with immediate (nearest) supertypeprivate short
depthFirstCode
private short
depthFirstNextSibling
private java.util.List<TypeImpl>
directSubtypes
private boolean
hasHashCodeLong
private long
hashCodeLong
private long
hashCodeNameLong
(package private) boolean
hasRefFeature
true for FSarrays non-arrays having 1 or more refs to FSs(package private) int
highestOffset
protected boolean
isBuiltIn
when set, processing skipped for - augment features from jcas - conformance checking between jcas and type system - validating the superclass chain upon load of jcas classprotected boolean
isCreatableAndNotBuiltinArray
False for non creatable (as Feature Structures) values (e.g.protected boolean
isFeatureFinal
protected boolean
isInheritanceFinal
protected boolean
isLongOrDouble
boolean
isRefType
false for primitives, strings, string subtypesprotected java.lang.Class<?>
javaClass
private java.lang.String
jcasClassName
private java.lang.String
name
(package private) int
nbrOfLongOrDoubleFeatures
(package private) int
nbrOfUsedIntDataSlots
The number of used slots needed = total number of features minus those represented by fields in JCas cover classes(package private) int
nbrOfUsedRefDataSlots
private java.lang.String
shortName
static TypeImpl
singleton
A special instance used in CasCopier to identify a missing type(package private) SlotKinds.SlotKind
slotKind
private java.util.Map<java.lang.String,FeatureImpl>
staticMergedFeatures
private java.util.List<FeatureImpl>
staticMergedFeaturesIntroducedByThisType
private FeatureImpl[]
staticMergedFeaturesList
private FeatureImpl[]
staticMergedIntFeaturesList
Map from adjusted offset in int features to feature.private FeatureImpl[]
staticMergedNonSofaFsRefs
Just the FS refs which are not sofa refsprivate FeatureImpl[]
staticMergedRefFeaturesList
Map from adjusted offset in ref features to feature Set at commit timeprivate TypeImpl
superType
private TypeSystemImpl
tsi
private short
typeCode
-
Constructor Summary
Constructors Modifier Constructor Description private
TypeImpl()
(package private)
TypeImpl(java.lang.String name, TypeSystemImpl tsi, TypeImpl supertype)
Create a new type.(package private)
TypeImpl(java.lang.String name, TypeSystemImpl tsi, TypeImpl supertype, java.lang.Class<?> javaClass)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description (package private) void
addFeature(FeatureImpl fi)
private void
appendIntroFeats(java.lang.StringBuilder sb, int indent)
private void
checkAndAdjustFeatureInSubtypes(TypeImpl ti, FeatureImpl fi)
It is possible that users may create type/subtype structure, and then add features (in any order) to that, including adding a subtype feature "foo", and subsequently adding a type feature "foo".(package private) void
checkExistingFeatureCompatible(FeatureImpl existingFi, Type range)
int
compareTo(TypeImpl t)
compareTo must return 0 for "equal" types equal means same name, same flags, same supertype chain, same subtypes, and same features Makes use of hashcodelong to probablistically shortcut computation for equal case for not equal types, do by parts(package private) int
computeDepthFirstCode(int level)
private long
computeHashCodeLong()
works across type systems a long so the hash code can be reliably used for quick equal compare.private void
computeHasXxx()
Sets hasRefFeature and nbrOfLongOrDoubleFeaturesprivate void
computeStaticMergedFeaturesList()
(package private) TypeImpl
consolidateType(TypeImpl topType, TypeImpl fsArrayType)
Consolidate arrays of fsRefs to fsArrayType and ordinary fsRefs to TOP for generic getters and settersboolean
equals(java.lang.Object obj)
Equal TypeImpl.(package private) int
getAdjOffset(java.lang.String featureShortName)
(package private) java.util.stream.Stream<TypeImpl>
getAllSubtypes()
(package private) TypeImpl[]
getAllSuperTypes()
java.util.Vector<Feature>
getAppropriateFeatures()
Deprecated.usegetFeatures()
int
getCode()
Return the internal integer code for this type.SlotKinds.SlotKind
getComponentSlotKind()
TypeImpl
getComponentType()
For array types, returns the component type of the array type.(package private) java.util.List<TypeImpl>
getDirectSubtypes()
Feature
getFeature(java.lang.String featureName)
Deprecated.use getFeatureByBaseName instead(package private) FeatureImpl
getFeatureByAdjOffset(int adjOffset, boolean isInInt)
FeatureImpl
getFeatureByBaseName(java.lang.String featureShortName)
Retrieve a feature for this type.FeatureImpl[]
getFeatureImpls()
This impl depends on features never being removed from types, only added Minimal Java object generation, maximal reusejava.util.List<Feature>
getFeatures()
guaranteed to be non-null, but might be empty listjava.util.stream.Stream<FeatureImpl>
getFeaturesAsStream()
int
getFsSpaceReq()
Get the v2 heap size for types with featuresint
getFsSpaceReq(int length)
get the v2 heap size for typesint
getFsSpaceReq(TOP fs)
(package private) java.lang.Class<?>
getJavaClass()
Of limited use because the java class value, over time, is multi- valued; e.g.java.lang.String
getJCasClassName()
java.util.List<FeatureImpl>
getMergedStaticFeaturesIntroducedByThisType()
java.lang.String
getName()
Get the name of the type.int
getNbrOfLongOrDoubleFeatures()
int
getNumberOfFeatures()
Get the number of features for which this type defines the range.java.lang.String
getShortName()
Get the unqualified, short name of this type.(package private) FeatureImpl[]
getStaticMergedNonSofaFsRefs()
TypeImpl
getSuperType()
Get the super type.TypeSystemImpl
getTypeSystem()
Get the type hierarchy that this type belongs to.int
hashCode()
private long
hashCodeLong()
long
hashCodeNameLong()
boolean
hasRefFeature()
(package private) boolean
hasSupertype(TypeImpl supertype)
(package private) void
initAdjOffset2FeatureMaps(java.util.List<FeatureImpl> tempIntFis, java.util.List<FeatureImpl> tempRefFis, java.util.List<FeatureImpl> tempNsr)
boolean
isAnnotationBaseType()
boolean
isAnnotationType()
Check if this is an annotation type.boolean
isAppropriateFeature(Feature feature)
boolean
isArray()
Check if the type is an array type.(package private) boolean
isAuxStoredArray()
model how v2 stores this - needed for backward compatibility / (de)serializationboolean
isCreatableAndNotBuiltinArray()
boolean
isFeatureFinal()
Check if type is feature final, i.e., if no more new features may be defined for it.(package private) boolean
isHeapStoredArray()
model how v2 stores this - needed for backward compatibility / (de)serializationboolean
isInheritanceFinal()
Check if type is inheritance final, i.e., if new types can be derived from it.boolean
isLongOrDouble()
boolean
isPrimitive()
Check if the type is one of the primitive types.(package private) boolean
isPrimitiveArrayType()
boolean
isStringOrStringSubtype()
boolean
isStringSubtype()
Check if the type is a String subtype.boolean
isTopType()
boolean
isTypedFsArray()
java.util.Iterator<Feature>
iterator()
void
prettyPrint(java.lang.StringBuilder sb, int indent)
private <T> void
prettyPrintList(java.lang.StringBuilder sb, java.lang.String title, java.util.List<T> items, java.util.function.BiConsumer<java.lang.StringBuilder,T> appender)
void
prettyPrintWithSubTypes(java.lang.StringBuilder sb, int indent)
private void
removeEqualFeatureNameMatch(java.util.List<FeatureImpl> fiList, java.lang.String aName)
(package private) void
setBuiltIn()
(package private) void
setFeatureFinal()
(package private) void
setInheritanceFinal()
(package private) void
setJavaClass(java.lang.Class<?> javaClass)
(package private) void
setStaticMergedIntFeaturesList(FeatureImpl[] v)
(package private) void
setStaticMergedNonSofaFsRefs(FeatureImpl[] v)
(package private) void
setStaticMergedRefFeaturesList(FeatureImpl[] v)
boolean
subsumes(TypeImpl ti)
boolean
subsumesStrictly(TypeImpl ti)
boolean
subsumesValue(java.lang.Object v)
java.lang.String
toString()
java.lang.String
toString(int indent)
-
-
-
Field Detail
-
name
private final java.lang.String name
-
shortName
private final java.lang.String shortName
-
jcasClassName
private final java.lang.String jcasClassName
-
typeCode
private final short typeCode
-
depthFirstCode
private short depthFirstCode
-
depthFirstNextSibling
private short depthFirstNextSibling
-
tsi
private final TypeSystemImpl tsi
-
slotKind
final SlotKinds.SlotKind slotKind
-
javaClass
protected java.lang.Class<?> javaClass
-
isFeatureFinal
protected boolean isFeatureFinal
-
isInheritanceFinal
protected boolean isInheritanceFinal
-
isLongOrDouble
protected final boolean isLongOrDouble
-
isBuiltIn
protected boolean isBuiltIn
when set, processing skipped for - augment features from jcas - conformance checking between jcas and type system - validating the superclass chain upon load of jcas class
-
nbrOfLongOrDoubleFeatures
int nbrOfLongOrDoubleFeatures
-
isCreatableAndNotBuiltinArray
protected final boolean isCreatableAndNotBuiltinArray
False for non creatable (as Feature Structures) values (e.g. byte, integer, string) and also false for array built-ins (which can be Feature Structures, can be added-to-indexes, etc.)
-
isRefType
public final boolean isRefType
false for primitives, strings, string subtypes
-
hasRefFeature
boolean hasRefFeature
true for FSarrays non-arrays having 1 or more refs to FSs
-
superType
private final TypeImpl superType
-
allSuperTypes
private final TypeImpl[] allSuperTypes
All supertypes, in order, starting with immediate (nearest) supertype
-
directSubtypes
private final java.util.List<TypeImpl> directSubtypes
-
staticMergedFeatures
private final java.util.Map<java.lang.String,FeatureImpl> staticMergedFeatures
-
staticMergedFeaturesList
private FeatureImpl[] staticMergedFeaturesList
-
staticMergedFeaturesIntroducedByThisType
private final java.util.List<FeatureImpl> staticMergedFeaturesIntroducedByThisType
-
staticMergedIntFeaturesList
private FeatureImpl[] staticMergedIntFeaturesList
Map from adjusted offset in int features to feature. Corrects for Long/Double values taking 2 int slots. Set at commit time
-
staticMergedRefFeaturesList
private FeatureImpl[] staticMergedRefFeaturesList
Map from adjusted offset in ref features to feature Set at commit time
-
staticMergedNonSofaFsRefs
private FeatureImpl[] staticMergedNonSofaFsRefs
Just the FS refs which are not sofa refs
-
nbrOfUsedIntDataSlots
int nbrOfUsedIntDataSlots
The number of used slots needed = total number of features minus those represented by fields in JCas cover classes
-
nbrOfUsedRefDataSlots
int nbrOfUsedRefDataSlots
-
highestOffset
int highestOffset
-
singleton
public static final TypeImpl singleton
A special instance used in CasCopier to identify a missing type
-
hashCodeLong
private long hashCodeLong
-
hashCodeNameLong
private final long hashCodeNameLong
-
hasHashCodeLong
private boolean hasHashCodeLong
-
-
Constructor Detail
-
TypeImpl
private TypeImpl()
-
TypeImpl
TypeImpl(java.lang.String name, TypeSystemImpl tsi, TypeImpl supertype)
Create a new type. This should only be done by aTypeSystemImpl
.
-
TypeImpl
TypeImpl(java.lang.String name, TypeSystemImpl tsi, TypeImpl supertype, java.lang.Class<?> javaClass)
-
-
Method Detail
-
getName
public java.lang.String getName()
Get the name of the type.
-
getJCasClassName
public java.lang.String getJCasClassName()
-
getSuperType
public TypeImpl getSuperType()
Get the super type.- Returns:
- The super type or null for Top.
-
getCode
public int getCode()
Return the internal integer code for this type. This is only useful if you want to work with the low-level API.- Returns:
- The internal code for this type,
>=0
.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toString
public java.lang.String toString(int indent)
-
prettyPrintList
private <T> void prettyPrintList(java.lang.StringBuilder sb, java.lang.String title, java.util.List<T> items, java.util.function.BiConsumer<java.lang.StringBuilder,T> appender)
-
prettyPrint
public void prettyPrint(java.lang.StringBuilder sb, int indent)
-
prettyPrintWithSubTypes
public void prettyPrintWithSubTypes(java.lang.StringBuilder sb, int indent)
-
appendIntroFeats
private void appendIntroFeats(java.lang.StringBuilder sb, int indent)
-
getAppropriateFeatures
@Deprecated public java.util.Vector<Feature> getAppropriateFeatures()
Deprecated.usegetFeatures()
Get a vector of the features for which this type is the domain. Features will be returned in no particular order.- Specified by:
getAppropriateFeatures
in interfaceType
- Returns:
- The vector.
-
getNumberOfFeatures
public int getNumberOfFeatures()
Get the number of features for which this type defines the range.- Specified by:
getNumberOfFeatures
in interfaceType
- Returns:
- The number of features.
-
isAppropriateFeature
public boolean isAppropriateFeature(Feature feature)
-
isAnnotationType
public boolean isAnnotationType()
Check if this is an annotation type.- Returns:
true
, ifthis
is an annotation type or subtype;false
, else.
-
isAnnotationBaseType
public boolean isAnnotationBaseType()
- Returns:
- true for AnnotationBaseType or any subtype
-
isCreatableAndNotBuiltinArray
public boolean isCreatableAndNotBuiltinArray()
-
getTypeSystem
public TypeSystemImpl getTypeSystem()
Get the type hierarchy that this type belongs to.- Returns:
- The type hierarchy.
-
getFeatureByBaseName
public FeatureImpl getFeatureByBaseName(java.lang.String featureShortName)
Description copied from interface:Type
Retrieve a feature for this type. Inherited features can also be retrieved this way.- Specified by:
getFeatureByBaseName
in interfaceType
- Parameters:
featureShortName
- The short, unqualified name of the feature.- Returns:
- The feature, if it exists;
null
, else. - See Also:
Type.getFeatureByBaseName(String)
-
getShortName
public java.lang.String getShortName()
Description copied from interface:Type
Get the unqualified, short name of this type.- Specified by:
getShortName
in interfaceType
- Returns:
- The short name of this type.
- See Also:
Type.getShortName()
-
isFeatureFinal
public boolean isFeatureFinal()
Description copied from interface:Type
Check if type is feature final, i.e., if no more new features may be defined for it.- Specified by:
isFeatureFinal
in interfaceType
- Returns:
- If type is feature final.
- See Also:
Type.isFeatureFinal()
-
isInheritanceFinal
public boolean isInheritanceFinal()
Description copied from interface:Type
Check if type is inheritance final, i.e., if new types can be derived from it.- Specified by:
isInheritanceFinal
in interfaceType
- Returns:
- If type is inheritance final.
- See Also:
Type.isInheritanceFinal()
-
setFeatureFinal
void setFeatureFinal()
-
setInheritanceFinal
void setInheritanceFinal()
-
setBuiltIn
void setBuiltIn()
-
isLongOrDouble
public boolean isLongOrDouble()
-
getFeature
@Deprecated public Feature getFeature(java.lang.String featureName)
Deprecated.use getFeatureByBaseName instead- Parameters:
featureName
- -- Returns:
- -
-
getFeatures
public java.util.List<Feature> getFeatures()
guaranteed to be non-null, but might be empty list- Specified by:
getFeatures
in interfaceType
- Returns:
- -
-
getFeatureImpls
public FeatureImpl[] getFeatureImpls()
This impl depends on features never being removed from types, only added Minimal Java object generation, maximal reuse- Returns:
- the list of feature impls
-
computeStaticMergedFeaturesList
private void computeStaticMergedFeaturesList()
-
computeHasXxx
private void computeHasXxx()
Sets hasRefFeature and nbrOfLongOrDoubleFeatures
-
getFeaturesAsStream
public java.util.stream.Stream<FeatureImpl> getFeaturesAsStream()
-
getMergedStaticFeaturesIntroducedByThisType
public java.util.List<FeatureImpl> getMergedStaticFeaturesIntroducedByThisType()
-
addFeature
void addFeature(FeatureImpl fi)
- Parameters:
fi
- feature to be added
-
checkAndAdjustFeatureInSubtypes
private void checkAndAdjustFeatureInSubtypes(TypeImpl ti, FeatureImpl fi)
It is possible that users may create type/subtype structure, and then add features (in any order) to that, including adding a subtype feature "foo", and subsequently adding a type feature "foo". To handle this: a feature added to type T should be - removed if present in all subtype's introfeatures - added to all subtypes merged features - a check done in case any of the subtypes had already added this, but with a different definition- Parameters:
ti
- the type whose subtypes need checkingfi
- the feature
-
removeEqualFeatureNameMatch
private void removeEqualFeatureNameMatch(java.util.List<FeatureImpl> fiList, java.lang.String aName)
-
checkExistingFeatureCompatible
void checkExistingFeatureCompatible(FeatureImpl existingFi, Type range)
-
consolidateType
TypeImpl consolidateType(TypeImpl topType, TypeImpl fsArrayType)
Consolidate arrays of fsRefs to fsArrayType and ordinary fsRefs to TOP for generic getters and setters- Parameters:
topType
- -fsArrayType
- -- Returns:
- this type or one of the two passed in types
-
isPrimitive
public boolean isPrimitive()
Description copied from interface:Type
Check if the type is one of the primitive types.- Specified by:
isPrimitive
in interfaceType
- Returns:
true
iff type is a primitive type.- See Also:
Type.isPrimitive()
-
isArray
public boolean isArray()
Description copied from interface:Type
Check if the type is an array type.- Specified by:
isArray
in interfaceType
- Returns:
true
iff the type is an array type.- See Also:
Type.isArray()
-
isHeapStoredArray
boolean isHeapStoredArray()
model how v2 stores this - needed for backward compatibility / (de)serialization- Returns:
- true if it is an array and is stored in the main heap (int, float, or string)
-
isAuxStoredArray
boolean isAuxStoredArray()
model how v2 stores this - needed for backward compatibility / (de)serialization- Returns:
- true if it is an array and is one of the 3 aux arrays (byte (also used for boolean) short, long
-
isStringSubtype
public boolean isStringSubtype()
Description copied from interface:Type
Check if the type is a String subtype. Note: returns false if a plain string- Specified by:
isStringSubtype
in interfaceType
- Returns:
true
iff the type is a String subtype type; false for plain string- See Also:
Type.isStringSubtype()
-
isStringOrStringSubtype
public boolean isStringOrStringSubtype()
- Specified by:
isStringOrStringSubtype
in interfaceType
- Returns:
- true if is a String or a StringSubtype
-
getComponentType
public TypeImpl getComponentType()
Description copied from interface:Type
For array types, returns the component type of the array type. For all other types, it will returnnull
.- Specified by:
getComponentType
in interfaceType
- Returns:
- The component type of an array type.
-
getComponentSlotKind
public SlotKinds.SlotKind getComponentSlotKind()
-
getAllSubtypes
java.util.stream.Stream<TypeImpl> getAllSubtypes()
- Returns:
- stream of all subtypes (excludes this type) in strict subsumption order
-
getDirectSubtypes
java.util.List<TypeImpl> getDirectSubtypes()
-
hasSupertype
boolean hasSupertype(TypeImpl supertype)
-
getAllSuperTypes
TypeImpl[] getAllSuperTypes()
-
subsumes
public boolean subsumes(TypeImpl ti)
- Parameters:
ti
- the subtype to check- Returns:
- true if this type subsumes the subtype (is equal to or a supertype of the subtype)
-
subsumesStrictly
public boolean subsumesStrictly(TypeImpl ti)
- Parameters:
ti
- the subtype to check- Returns:
- true if this type subsumes the subtype (is equal to or a supertype of the subtype)
-
subsumesValue
public boolean subsumesValue(java.lang.Object v)
- Parameters:
v
- the value to test- Returns:
- true if value v can be assigned to an object of this type
-
computeDepthFirstCode
int computeDepthFirstCode(int level)
-
getJavaClass
java.lang.Class<?> getJavaClass()
Of limited use because the java class value, over time, is multi- valued; e.g. when PEARs are in use, or different extension classpaths are in use for multiple pipelines.- Returns:
- the javaClass
-
setJavaClass
void setJavaClass(java.lang.Class<?> javaClass)
- Parameters:
javaClass
- the javaClass to set
-
getFsSpaceReq
public int getFsSpaceReq()
Get the v2 heap size for types with features- Returns:
- the main heap size for this FeatureStructure, assuming it's not a heap stored array (see below)
-
getFsSpaceReq
public int getFsSpaceReq(int length)
get the v2 heap size for types- Parameters:
length
- for heap-stored arrays, the array length- Returns:
- the main heap size for this FeatureStructure
-
getFsSpaceReq
public int getFsSpaceReq(TOP fs)
-
initAdjOffset2FeatureMaps
void initAdjOffset2FeatureMaps(java.util.List<FeatureImpl> tempIntFis, java.util.List<FeatureImpl> tempRefFis, java.util.List<FeatureImpl> tempNsr)
-
getFeatureByAdjOffset
FeatureImpl getFeatureByAdjOffset(int adjOffset, boolean isInInt)
-
getAdjOffset
int getAdjOffset(java.lang.String featureShortName)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
hashCodeLong
private long hashCodeLong()
-
hashCodeNameLong
public long hashCodeNameLong()
-
computeHashCodeLong
private long computeHashCodeLong()
works across type systems a long so the hash code can be reliably used for quick equal compare. Hash code is not a function of subtypes; otherwise two Type Systems with different types would have unequal TOP types, for example- Returns:
- -
-
equals
public boolean equals(java.lang.Object obj)
Equal TypeImpl. Works across type systems.- Overrides:
equals
in classjava.lang.Object
-
compareTo
public int compareTo(TypeImpl t)
compareTo must return 0 for "equal" types equal means same name, same flags, same supertype chain, same subtypes, and same features Makes use of hashcodelong to probablistically shortcut computation for equal case for not equal types, do by parts- Specified by:
compareTo
in interfacejava.lang.Comparable<TypeImpl>
-
isPrimitiveArrayType
boolean isPrimitiveArrayType()
-
hasRefFeature
public boolean hasRefFeature()
-
getNbrOfLongOrDoubleFeatures
public int getNbrOfLongOrDoubleFeatures()
-
isTypedFsArray
public boolean isTypedFsArray()
- Returns:
- true if this type is an array of specific (not TOP) Feature structures, not FSArray
-
setStaticMergedIntFeaturesList
void setStaticMergedIntFeaturesList(FeatureImpl[] v)
-
setStaticMergedRefFeaturesList
void setStaticMergedRefFeaturesList(FeatureImpl[] v)
-
setStaticMergedNonSofaFsRefs
void setStaticMergedNonSofaFsRefs(FeatureImpl[] v)
-
getStaticMergedNonSofaFsRefs
FeatureImpl[] getStaticMergedNonSofaFsRefs()
-
isTopType
public boolean isTopType()
-
-