Class CharArraySet
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<java.lang.Object>
-
- org.apache.lucene.analysis.util.CharArraySet
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>,java.util.Collection<java.lang.Object>,java.util.Set<java.lang.Object>
public class CharArraySet extends java.util.AbstractSet<java.lang.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.You must specify the required
Versioncompatibility when creatingCharArraySet:- As of 3.1, supplementary characters are properly lowercased.
CharArraySetwith the behavior before Lucene 3.1 pass aVersion< 3.1 to the constructors.Please note: This class implements
Setbut 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 CharArraySetEMPTY_SET
-
Constructor Summary
Constructors Constructor Description CharArraySet(Version matchVersion, int startSize, boolean ignoreCase)Create set with enough capacity to hold startSize termsCharArraySet(Version matchVersion, java.util.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 booleanadd(char[] text)Add this char[] directly to the set.booleanadd(java.lang.CharSequence text)Add this CharSequence into the setbooleanadd(java.lang.Object o)booleanadd(java.lang.String text)Add 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(java.lang.CharSequence cs)true if theCharSequenceis in the setbooleancontains(java.lang.Object o)static CharArraySetcopy(Version matchVersion, java.util.Set<?> set)Returns a copy of the given set as aCharArraySet.java.util.Iterator<java.lang.Object>iterator()Returns anIteratorforchar[]instances in this set.intsize()java.lang.StringtoString()static CharArraySetunmodifiableSet(CharArraySet set)Returns an unmodifiableCharArraySet.
-
-
-
Field Detail
-
EMPTY_SET
public static final CharArraySet EMPTY_SET
-
-
Constructor Detail
-
CharArraySet
public CharArraySet(Version matchVersion, int startSize, boolean ignoreCase)
Create set with enough capacity to hold startSize terms- Parameters:
matchVersion- compatibility match version see Version note above for details.startSize- the initial capacityignoreCase-falseif and only if the set should be case sensitive otherwisetrue.
-
CharArraySet
public CharArraySet(Version matchVersion, java.util.Collection<?> c, boolean ignoreCase)
Creates a set from a Collection of objects.- Parameters:
matchVersion- compatibility match version see Version note above for details.c- a collection whose elements to be placed into the setignoreCase-falseif 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:
clearin interfacejava.util.Collection<java.lang.Object>- Specified by:
clearin interfacejava.util.Set<java.lang.Object>- Overrides:
clearin classjava.util.AbstractCollection<java.lang.Object>
-
contains
public boolean contains(char[] text, int off, int len)true if thelenchars oftextstarting atoffare in the set
-
contains
public boolean contains(java.lang.CharSequence cs)
true if theCharSequenceis in the set
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<java.lang.Object>- Specified by:
containsin interfacejava.util.Set<java.lang.Object>- Overrides:
containsin classjava.util.AbstractCollection<java.lang.Object>
-
add
public boolean add(java.lang.Object o)
- Specified by:
addin interfacejava.util.Collection<java.lang.Object>- Specified by:
addin interfacejava.util.Set<java.lang.Object>- Overrides:
addin classjava.util.AbstractCollection<java.lang.Object>
-
add
public boolean add(java.lang.CharSequence text)
Add this CharSequence into the set
-
add
public boolean add(java.lang.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:
sizein interfacejava.util.Collection<java.lang.Object>- Specified by:
sizein interfacejava.util.Set<java.lang.Object>- Specified by:
sizein classjava.util.AbstractCollection<java.lang.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:
java.lang.NullPointerException- if the given set isnull.
-
copy
public static CharArraySet copy(Version matchVersion, java.util.Set<?> set)
Returns a copy of the given set as aCharArraySet. If the given set is aCharArraySetthe ignoreCase property will be preserved.Note: If you intend to create a copy of another
CharArraySetwhere theVersionof the source set differs from its copyCharArraySet(Version, Collection, boolean)should be used instead. Thecopy(Version, Set)will preserve theVersionof the source set it is an instance ofCharArraySet.- Parameters:
matchVersion- compatibility match version see Version note above for details. This argument will be ignored if the given set is aCharArraySet.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
public java.util.Iterator<java.lang.Object> iterator()
Returns anIteratorforchar[]instances in this set.- Specified by:
iteratorin interfacejava.util.Collection<java.lang.Object>- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.Object>- Specified by:
iteratorin interfacejava.util.Set<java.lang.Object>- Specified by:
iteratorin classjava.util.AbstractCollection<java.lang.Object>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractCollection<java.lang.Object>
-
-