Package org.apache.uima.cas.impl
Class FsIndex_iicp<T extends FeatureStructure>
- java.lang.Object
-
- java.util.AbstractCollection<T>
-
- org.apache.uima.cas.impl.FsIndex_iicp<T>
-
- All Implemented Interfaces:
java.lang.Comparable<FsIndex_iicp<? extends FeatureStructure>>,java.lang.Iterable<T>,java.util.Collection<T>,java.util.Comparator<FeatureStructure>,FSIndex<T>,LowLevelIndex<T>
- Direct Known Subclasses:
FsIndex_annotation
class FsIndex_iicp<T extends FeatureStructure> extends java.util.AbstractCollection<T> implements java.lang.Comparable<FsIndex_iicp<? extends FeatureStructure>>, java.util.Comparator<FeatureStructure>, LowLevelIndex<T>
FsIndex_iicp (iicp) A pair of an leaf index and an iterator cache. An iterator cache is the set of all leaf-indexes necessary to create an iterator for the type of the index. The cache includes the index for the type of this index, as well as all subtypes. compareTo() is based on types and the comparator of the index. T is the Java cover class of the top type (root) in the index set Also includes a lazily initialized reference to a corresponding FSIndexFlat instance. This class is package private to share with FSIndexFlat For Internal Use
-
-
Field Summary
Fields Modifier and Type Field Description (package private) FsIndex_singletype<TOP>[]cachedSubFsLeafIndexesA list of indexes (the sub-indexes that we need for an iterator).(package private) FsIndex_singletype<T>fsIndex_singletypeThe "root" index, i.e., index of the type of the iterator.(package private) FSIndexRepositoryImplfsIndexRepositoryImplprivate booleanisIteratorCacheSetup(package private) int[]sortedTypeCodesThe type codes corresponding to the cachedSubFsLeafIndexes, set up lazily-
Fields inherited from interface org.apache.uima.cas.FSIndex
BAG_INDEX, DEFAULT_BAG_INDEX, SET_INDEX, SORTED_INDEX
-
Fields inherited from interface org.apache.uima.cas.impl.LowLevelIndex
FS_ID_COMPARATOR, IS_ORDERED, IS_TYPE_ORDER
-
-
Constructor Summary
Constructors Constructor Description FsIndex_iicp(FsIndex_singletype<T> fsIndex_singletype)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidcollectCowIndexParts(java.util.ArrayList<CopyOnWriteIndexPart<T>> indexes)intcompare(FeatureStructure fs1, FeatureStructure fs2)Compare two feature structures according to the ordering relation of the index.intcompareTo(FsIndex_iicp<? extends FeatureStructure> cp)Maybe not used 3/2015 Compares two instances of FsIndex_iicp, for ordering.booleancontains(FeatureStructure fs)Check if the index contains an element equal to the given feature structure according to the comparators defined for this index.(package private) voidcreateIndexIteratorCache()booleanequals(java.lang.Object o)Two iicps are equal if and only if: - the types they index are the same, and - the comparators are equal, and - the indexing stragtegy (bag/set/sorted) are the same Used when creating the index iterator cache to select from the set of all instances of these the one that goes with the same index definition Used by CasComplete serialization to merge multiple index names referring to the same indexTfind(FeatureStructure fs)Find an entry in the index "equal to" the given feature structure according to the comparators specified for this index.CASImplgetCasImpl()java.util.Comparator<TOP>getComparator()FSIndexComparatorgetComparatorForIndexSpecs()This is **NOT** a comparator for Feature Structures, but rather something that compares two comparator specificationsFSIndexComparatorImplgetComparatorImplForIndexSpecs()(package private) FsIndex_singletype<T>getFsIndex_singleType()FSIndexRepositoryImplgetFsRepositoryImpl()intgetIndexingStrategy()Return the indexing strategy.(package private) LowLevelIterator<T>[]getIterators()TypegetType()Return the type of feature structures this index contains.(package private) intgetTypeCode()(package private) intguessedSize()A faster version of size() when there are lots of subtypes The cache must be already set up Guess by adding the sizes of up to the first 3 type/subtypes, then add 1 more for each subtype in addition.inthashCode()private voidinitOneTypeThenAllSubtypes(TypeImpl ti, java.util.ArrayList<FsIndex_singletype<FeatureStructure>> cache, int indexKind)This method inits one type then calls itself for all direct subtypes(package private) booleanisDefaultBagIndex()booleanisEmpty()(package private) booleanisSetIndex()booleanisSorted()LowLevelIterator<T>iterator()Iterator varieties All iterators are over a Type + subtypes (because that's the purpose of this class) - ambiguous / unambiguous (for AnnotationIndex) - not strict / strict (for AnnotationIndex) - ignoring type priorities or not (for any index) - "unordered" - no need to preserve order These may be combined.LowLevelIterator<T>iterator(boolean orderNotNeeded, boolean ignoreType)Internal use, used by select framework.intll_compare(int ref1, int ref2)Compare two Feature structures, referred to by IDsLowLevelIterator<T>ll_iterator(boolean ambiguous)Iterator over arbitrary Feature Structures, but also filters out non-AnnotationFS FeatureStructuresintll_maxAnnotSpan()intsize()Return the number of feature structures in this index.java.util.stream.Stream<FsIndex_singletype<TOP>>streamNonEmptyIndexes()java.lang.StringtoString()FSIndex<T>withSnapshotIterators()Creates a shared copy of this FSIndex configured to produce snapshot iterators that don't throw ConcurrentModificationExceptions.-
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, toArray, toArray
-
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Methods inherited from interface org.apache.uima.cas.impl.LowLevelIndex
flush, getIntIterator, getSubIndex, getSubIndex, ll_iterator, select, select, select, select, select
-
-
-
-
Field Detail
-
fsIndexRepositoryImpl
final FSIndexRepositoryImpl fsIndexRepositoryImpl
-
fsIndex_singletype
final FsIndex_singletype<T extends FeatureStructure> fsIndex_singletype
The "root" index, i.e., index of the type of the iterator. default visibility to make it accessible by FSIndexFlat
-
cachedSubFsLeafIndexes
FsIndex_singletype<TOP>[] cachedSubFsLeafIndexes
A list of indexes (the sub-indexes that we need for an iterator). I.e., one index for each type that's subsumed by the iterator's type; includes the iterator's type leaf index too. This is set up lazily on first need, to avoid extra work when won't be accessed
-
isIteratorCacheSetup
private volatile boolean isIteratorCacheSetup
-
sortedTypeCodes
int[] sortedTypeCodes
The type codes corresponding to the cachedSubFsLeafIndexes, set up lazily
-
-
Constructor Detail
-
FsIndex_iicp
FsIndex_iicp(FsIndex_singletype<T> fsIndex_singletype)
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractCollection<T extends FeatureStructure>
-
equals
public boolean equals(java.lang.Object o)
Two iicps are equal if and only if: - the types they index are the same, and - the comparators are equal, and - the indexing stragtegy (bag/set/sorted) are the same Used when creating the index iterator cache to select from the set of all instances of these the one that goes with the same index definition Used by CasComplete serialization to merge multiple index names referring to the same index- Specified by:
equalsin interfacejava.util.Collection<T extends FeatureStructure>- Specified by:
equalsin interfacejava.util.Comparator<T extends FeatureStructure>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Collection<T extends FeatureStructure>- Overrides:
hashCodein classjava.lang.Object
-
createIndexIteratorCache
void createIndexIteratorCache()
-
initOneTypeThenAllSubtypes
private void initOneTypeThenAllSubtypes(TypeImpl ti, java.util.ArrayList<FsIndex_singletype<FeatureStructure>> cache, int indexKind)
This method inits one type then calls itself for all direct subtypes- Parameters:
ti-cache-indexKind-
-
compareTo
public int compareTo(FsIndex_iicp<? extends FeatureStructure> cp)
Maybe not used 3/2015 Compares two instances of FsIndex_iicp, for ordering. Compares first using the type code of the main types If those are equal, Compares using the comparatorForIndexSpecs objects- Specified by:
compareToin interfacejava.lang.Comparable<T extends FeatureStructure>- See Also:
Comparable.compareTo(Object)
-
size
public int size()
Description copied from interface:FSIndexReturn the number of feature structures in this index.- Specified by:
sizein interfacejava.util.Collection<T extends FeatureStructure>- Specified by:
sizein interfaceFSIndex<T extends FeatureStructure>- Specified by:
sizein classjava.util.AbstractCollection<T extends FeatureStructure>- Returns:
- the sum of the sizes of the indexes of the type + all subtypes
-
ll_maxAnnotSpan
public int ll_maxAnnotSpan()
- Specified by:
ll_maxAnnotSpanin interfaceLowLevelIndex<T extends FeatureStructure>- Returns:
- for annotation indexes, an conservative estimate the maximum span between begin and end The value may be larger than actual.
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<T extends FeatureStructure>- Overrides:
isEmptyin classjava.util.AbstractCollection<T extends FeatureStructure>
-
guessedSize
int guessedSize()
A faster version of size() when there are lots of subtypes The cache must be already set up Guess by adding the sizes of up to the first 3 type/subtypes, then add 1 more for each subtype in addition.- Returns:
- a guess at the size, done quickly
-
getFsIndex_singleType
FsIndex_singletype<T> getFsIndex_singleType()
-
isDefaultBagIndex
boolean isDefaultBagIndex()
-
isSetIndex
boolean isSetIndex()
-
ll_compare
public int ll_compare(int ref1, int ref2)Description copied from interface:LowLevelIndexCompare two Feature structures, referred to by IDs- Specified by:
ll_comparein interfaceLowLevelIndex<T extends FeatureStructure>- Parameters:
ref1- -ref2- -- Returns:
- -
-
getIndexingStrategy
public int getIndexingStrategy()
Description copied from interface:FSIndexReturn the indexing strategy.- Specified by:
getIndexingStrategyin interfaceFSIndex<T extends FeatureStructure>- Returns:
- One of
SORTED_INDEX,BAG_INDEXorSET_INDEX.
-
getComparator
public java.util.Comparator<TOP> getComparator()
- Specified by:
getComparatorin interfaceLowLevelIndex<T extends FeatureStructure>- Returns:
- a comparator used by this index to compare Feature Structures For sets, the equal is used to determine set membership For sorted, the comparator is the sort order (this comparator is without the ID)
-
getComparatorForIndexSpecs
public FSIndexComparator getComparatorForIndexSpecs()
Description copied from interface:LowLevelIndexThis is **NOT** a comparator for Feature Structures, but rather something that compares two comparator specifications- Specified by:
getComparatorForIndexSpecsin interfaceLowLevelIndex<T extends FeatureStructure>- Returns:
- -
-
getComparatorImplForIndexSpecs
public FSIndexComparatorImpl getComparatorImplForIndexSpecs()
-
compare
public int compare(FeatureStructure fs1, FeatureStructure fs2)
Description copied from interface:FSIndexCompare two feature structures according to the ordering relation of the index. If the input feature structures are not of the type of the index or a supertype, the result is undefined. Because the indexes compare might use only features defined in supertypes, the arguments being compared could be supertypes of the indexed type.- Specified by:
comparein interfacejava.util.Comparator<T extends FeatureStructure>- Specified by:
comparein interfaceFSIndex<T extends FeatureStructure>- Parameters:
fs1- the first Feature Structure to comparefs2- the second Feature Structure to compare- Returns:
-1iffs1 < fs2;0iffs1 = fs2;1else.
-
contains
public boolean contains(FeatureStructure fs)
Description copied from interface:FSIndexCheck if the index contains an element equal to the given feature structure according to the comparators defined for this index. For bag indexes (which have no comparators), the equality test means the identical feature structure. Note that this is in general not the same as feature structure identity.
The element is used as a template, and may be a supertype of the type of the index, as long as the keys specified for this index can be accessed.
- Specified by:
containsin interfaceFSIndex<T extends FeatureStructure>- Parameters:
fs- A Feature Structure used a template to match for equality with the FSs in the index.- Returns:
trueif the index contains such an element.
-
find
public T find(FeatureStructure fs)
Description copied from interface:FSIndexFind an entry in the index "equal to" the given feature structure according to the comparators specified for this index. Note that this is in general not the same as feature structure identity. For BAG indexes, it is identity, for others it means the found feature structure compares equal with the parameter in terms of the defined comparators for the index. If there are multiple different FSs in the index which compare equal with the given feature structure, an arbitrary one is returned. This differs from the moveTo(fs) operation which guarantees to move to the first feature structure occurring in the index in this case.- Specified by:
findin interfaceFSIndex<T extends FeatureStructure>- Parameters:
fs- A Feature Structure used a template to match with the Feature Structures in the index. It must have the keys needed to do the compare as specified for the index that it's in.- Returns:
- A FS equal to the template argument, or
nullif no such FS exists. - See Also:
FSIterator.moveTo(FeatureStructure)
-
getType
public Type getType()
Description copied from interface:FSIndexReturn the type of feature structures this index contains.- Specified by:
getTypein interfaceFSIndex<T extends FeatureStructure>- Returns:
- The type of feature structures in this index.
-
getTypeCode
int getTypeCode()
-
getCasImpl
public CASImpl getCasImpl()
- Specified by:
getCasImplin interfaceLowLevelIndex<T extends FeatureStructure>- Returns:
- a CAS View associated with this iterator
-
isSorted
public boolean isSorted()
- Specified by:
isSortedin interfaceLowLevelIndex<T extends FeatureStructure>- Returns:
- true if the index is sorted
-
iterator
public LowLevelIterator<T> iterator()
Iterator varieties All iterators are over a Type + subtypes (because that's the purpose of this class) - ambiguous / unambiguous (for AnnotationIndex) - not strict / strict (for AnnotationIndex) - ignoring type priorities or not (for any index) - "unordered" - no need to preserve order These may be combined.- Specified by:
iteratorin interfacejava.util.Collection<T extends FeatureStructure>- Specified by:
iteratorin interfaceFSIndex<T extends FeatureStructure>- Specified by:
iteratorin interfacejava.lang.Iterable<T extends FeatureStructure>- Specified by:
iteratorin interfaceLowLevelIndex<T extends FeatureStructure>- Specified by:
iteratorin classjava.util.AbstractCollection<T extends FeatureStructure>- Returns:
- An FSIterator positioned at the beginning, or an invalid iterator.
-
iterator
public LowLevelIterator<T> iterator(boolean orderNotNeeded, boolean ignoreType)
Description copied from interface:LowLevelIndexInternal use, used by select framework. Return an iterator over the index. The position of the iterator will be set to return the first item in the index. If the index is empty, the iterator position will be marked as invalid.- Specified by:
iteratorin interfaceLowLevelIndex<T extends FeatureStructure>- Parameters:
orderNotNeeded- if true, skips work while iterating to keep iterators over multiple types in sync.ignoreType- if true, the comparator used for moveTo leftmost operations will ignore typeOrder keys, if the index happens to define these- Returns:
- An FSIterator positioned at the beginning, or an invalid iterator.
-
ll_iterator
public LowLevelIterator<T> ll_iterator(boolean ambiguous)
Iterator over arbitrary Feature Structures, but also filters out non-AnnotationFS FeatureStructures- Specified by:
ll_iteratorin interfaceLowLevelIndex<T extends FeatureStructure>- Parameters:
ambiguous- true for normal iteration, false to do unambiguous iteration- Returns:
- the iterator
-
withSnapshotIterators
public FSIndex<T> withSnapshotIterators()
Description copied from interface:FSIndexCreates a shared copy of this FSIndex configured to produce snapshot iterators that don't throw ConcurrentModificationExceptions.- Specified by:
withSnapshotIteratorsin interfaceFSIndex<T extends FeatureStructure>- Returns:
- a light-weight copy of this FSIndex, configured such that any iterator created using it will be a snapshot iterator - one where a snapshot is made of the state of the index at the time the iterator is created, and where subsequent modifications to the underlying index are allowed, but don't affect the iterator (which iterates over the read-only snapshot). Iterators produced with this won't throw ConcurrentModificationExceptions.
-
getFsRepositoryImpl
public FSIndexRepositoryImpl getFsRepositoryImpl()
-
streamNonEmptyIndexes
public java.util.stream.Stream<FsIndex_singletype<TOP>> streamNonEmptyIndexes()
- Returns:
- a stream of FSIndex_singletype, for all non-empty indexes
-
collectCowIndexParts
void collectCowIndexParts(java.util.ArrayList<CopyOnWriteIndexPart<T>> indexes)
-
getIterators
LowLevelIterator<T>[] getIterators()
-
-