Package org.apache.lucene.analysis
Class CharArraySet
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<Object>
-
- org.apache.lucene.analysis.CharArraySet
-
public class CharArraySet extends AbstractSet<Object>
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 isSet<Object>
, because you can add any object to it, that has a string representation. The add methods will useObject.toString()
and store the result using achar[]
buffer. The same behavior have thecontains()
methods. Theiterator()
returns anIterator<char[]>
.
-
-
Field Summary
Fields Modifier and Type Field Description static CharArraySet
EMPTY_SET
An emptyCharArraySet
.
-
Constructor Summary
Constructors Constructor Description CharArraySet(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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(char[] text)
Add this char[] directly to the set.boolean
add(CharSequence text)
Add this CharSequence into the setboolean
add(Object o)
boolean
add(String text)
Add this String into the setvoid
clear()
Clears all entries in this set.boolean
contains(char[] text, int off, int len)
true if thelen
chars oftext
starting atoff
are in the setboolean
contains(CharSequence cs)
true if theCharSequence
is in the setboolean
contains(Object o)
static CharArraySet
copy(Set<?> set)
Returns a copy of the given set as aCharArraySet
.Iterator<Object>
iterator()
Returns anIterator
forchar[]
instances in this set.int
size()
String
toString()
static CharArraySet
unmodifiableSet(CharArraySet set)
Returns an unmodifiableCharArraySet
.-
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, 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
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
addAll, containsAll, isEmpty, remove, retainAll, spliterator, toArray, toArray
-
-
-
-
Field Detail
-
EMPTY_SET
public static final CharArraySet EMPTY_SET
An emptyCharArraySet
.
-
-
Constructor Detail
-
CharArraySet
public CharArraySet(int startSize, boolean ignoreCase)
Create set with enough capacity to hold startSize terms- Parameters:
startSize
- the initial capacityignoreCase
-false
if and only if the set should be case sensitive otherwisetrue
.
-
CharArraySet
public CharArraySet(Collection<?> c, boolean ignoreCase)
Creates a set from a Collection of objects.- Parameters:
c
- a collection whose elements to be placed into the setignoreCase
-false
if and only if the set should be case sensitive otherwisetrue
.
-
-
Method Detail
-
clear
public void clear()
Clears all entries in this set. This method is supported for reusing, but notSet.remove(java.lang.Object)
.- Specified by:
clear
in interfaceCollection<Object>
- Specified by:
clear
in interfaceSet<Object>
- Overrides:
clear
in classAbstractCollection<Object>
-
contains
public boolean contains(char[] text, int off, int len)
true if thelen
chars oftext
starting atoff
are in the set
-
contains
public boolean contains(CharSequence cs)
true if theCharSequence
is in the set
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<Object>
- Specified by:
contains
in interfaceSet<Object>
- Overrides:
contains
in classAbstractCollection<Object>
-
add
public boolean add(Object o)
- Specified by:
add
in interfaceCollection<Object>
- Specified by:
add
in interfaceSet<Object>
- Overrides:
add
in classAbstractCollection<Object>
-
add
public boolean add(CharSequence text)
Add this CharSequence into the set
-
add
public boolean add(String text)
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:
size
in interfaceCollection<Object>
- Specified by:
size
in interfaceSet<Object>
- Specified by:
size
in classAbstractCollection<Object>
-
unmodifiableSet
public static CharArraySet unmodifiableSet(CharArraySet set)
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
public static CharArraySet copy(Set<?> set)
Returns a copy of the given set as aCharArraySet
. If the given set is aCharArraySet
the 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 aCharArraySet
the ignoreCase property as well as the matchVersion will be of the given set will be preserved.
-
toString
public String toString()
- Overrides:
toString
in classAbstractCollection<Object>
-
-