Package org.apache.lucene.analysis
Class CharArraySet
A simple class that stores Strings as char[]'s in a
hash table. Note that this is not a general purpose
class. For example, it cannot remove items from the
set, nor does it resize its hash table to be smaller,
etc. It is designed to be quick to test if a char[]
is in the set without the necessity of converting it
to a String first.
Please note: This class implements Set but
does not behave like it should in all cases. The generic type is
Set<Object>, because you can add any object to it,
that has a string representation. The add methods will use
Object.toString() and store the result using a char[]
buffer. The same behavior have the contains() methods.
The iterator() returns an Iterator<char[]>.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharArraySetAn emptyCharArraySet.private final CharArrayMap<Object> private static final Object -
Constructor Summary
ConstructorsConstructorDescriptionCharArraySet(int startSize, boolean ignoreCase) Create set with enough capacity to hold startSize termsCharArraySet(Collection<?> c, boolean ignoreCase) Creates a set from a Collection of objects.CharArraySet(CharArrayMap<Object> map) Create set from the specified map (internal only), used also byCharArrayMap.keySet() -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(char[] text) Add this char[] directly to the set.booleanadd(CharSequence text) Add this CharSequence into the setbooleanbooleanAdd this String into the setvoidclear()Clears all entries in this set.booleancontains(char[] text, int off, int len) true if thelenchars oftextstarting atoffare in the setbooleancontains(CharSequence cs) true if theCharSequenceis in the setbooleanstatic CharArraySetReturns a copy of the given set as aCharArraySet.iterator()Returns anIteratorforchar[]instances in this set.intsize()toString()static CharArraySetReturns an unmodifiableCharArraySet.Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAllMethods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, streamMethods inherited from interface java.util.Set
addAll, containsAll, isEmpty, remove, retainAll, spliterator, toArray, toArray
-
Field Details
-
EMPTY_SET
An emptyCharArraySet. -
PLACEHOLDER
-
map
-
-
Constructor Details
-
CharArraySet
public CharArraySet(int startSize, boolean ignoreCase) Create set with enough capacity to hold startSize terms- Parameters:
startSize- the initial capacityignoreCase-falseif and only if the set should be case sensitive otherwisetrue.
-
CharArraySet
Creates a set from a Collection of objects.- Parameters:
c- a collection whose elements to be placed into the setignoreCase-falseif and only if the set should be case sensitive otherwisetrue.
-
CharArraySet
CharArraySet(CharArrayMap<Object> map) Create set from the specified map (internal only), used also byCharArrayMap.keySet()
-
-
Method Details
-
clear
public void clear()Clears all entries in this set. This method is supported for reusing, but notSet.remove(java.lang.Object).- Specified by:
clearin interfaceCollection<Object>- Specified by:
clearin interfaceSet<Object>- Overrides:
clearin classAbstractCollection<Object>
-
contains
public boolean contains(char[] text, int off, int len) true if thelenchars oftextstarting atoffare in the set -
contains
true if theCharSequenceis in the set -
contains
- Specified by:
containsin interfaceCollection<Object>- Specified by:
containsin interfaceSet<Object>- Overrides:
containsin classAbstractCollection<Object>
-
add
- Specified by:
addin interfaceCollection<Object>- Specified by:
addin interfaceSet<Object>- Overrides:
addin classAbstractCollection<Object>
-
add
Add this CharSequence into the set -
add
Add this String into the set -
add
public boolean add(char[] text) Add this char[] directly to the set. If ignoreCase is true for this Set, the text array will be directly modified. The user should never modify this text array after calling this method. -
size
public int size()- Specified by:
sizein interfaceCollection<Object>- Specified by:
sizein interfaceSet<Object>- Specified by:
sizein classAbstractCollection<Object>
-
unmodifiableSet
Returns an unmodifiableCharArraySet. This allows to provide unmodifiable views of internal sets for "read-only" use.- Parameters:
set- a set for which the unmodifiable set is returned.- Returns:
- an new unmodifiable
CharArraySet. - Throws:
NullPointerException- if the given set isnull.
-
copy
Returns a copy of the given set as aCharArraySet. If the given set is aCharArraySetthe ignoreCase property will be preserved.- Parameters:
set- a set to copy- Returns:
- a copy of the given set as a
CharArraySet. If the given set is aCharArraySetthe ignoreCase property as well as the matchVersion will be of the given set will be preserved.
-
iterator
Returns anIteratorforchar[]instances in this set. -
toString
- Overrides:
toStringin classAbstractCollection<Object>
-