org.apache.lucene.analysis
Class CharArraySet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<Object>
          extended by org.apache.lucene.analysis.CharArraySet
All Implemented Interfaces:
Iterable<Object>, Collection<Object>, Set<Object>

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 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 behaviour have the contains() methods. The iterator() returns an Iterator<String>. For type safety also stringIterator() is provided.


Nested Class Summary
 class CharArraySet.CharArraySetIterator
          The Iterator for this set.
 
Field Summary
static CharArraySet EMPTY_SET
           
 
Constructor Summary
CharArraySet(Collection<? extends Object> c, boolean ignoreCase)
          Create set from a Collection of char[] or String
CharArraySet(int startSize, boolean ignoreCase)
          Create set with enough capacity to hold startSize terms
 
Method Summary
 boolean add(char[] text)
          Add this char[] directly to the set.
 boolean add(CharSequence text)
          Add this CharSequence into the set
 boolean add(Object o)
           
 boolean add(String text)
          Add this String into the set
 boolean contains(char[] text, int off, int len)
          true if the len chars of text starting at off are in the set
 boolean contains(CharSequence cs)
          true if the CharSequence is in the set
 boolean contains(Object o)
           
static CharArraySet copy(Set<?> set)
          Returns a copy of the given set as a CharArraySet.
 boolean isEmpty()
           
 Iterator<Object> iterator()
          returns an iterator of new allocated Strings, this method violates the Set interface
 int size()
           
 Iterator<String> stringIterator()
          returns an iterator of new allocated Strings
static CharArraySet unmodifiableSet(CharArraySet set)
          Returns an unmodifiable CharArraySet.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, remove, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, clear, containsAll, remove, retainAll, toArray, toArray
 

Field Detail

EMPTY_SET

public static final CharArraySet EMPTY_SET
Constructor Detail

CharArraySet

public CharArraySet(int startSize,
                    boolean ignoreCase)
Create set with enough capacity to hold startSize terms


CharArraySet

public CharArraySet(Collection<? extends Object> c,
                    boolean ignoreCase)
Create set from a Collection of char[] or String

Method Detail

contains

public boolean contains(char[] text,
                        int off,
                        int len)
true if the len chars of text starting at off are in the set


contains

public boolean contains(CharSequence cs)
true if the CharSequence is in the set


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 interface Collection<Object>
Specified by:
size in interface Set<Object>
Specified by:
size in class AbstractCollection<Object>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<Object>
Specified by:
isEmpty in interface Set<Object>
Overrides:
isEmpty in class AbstractCollection<Object>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<Object>
Specified by:
contains in interface Set<Object>
Overrides:
contains in class AbstractCollection<Object>

add

public boolean add(Object o)
Specified by:
add in interface Collection<Object>
Specified by:
add in interface Set<Object>
Overrides:
add in class AbstractCollection<Object>

unmodifiableSet

public static CharArraySet unmodifiableSet(CharArraySet set)
Returns an unmodifiable CharArraySet. 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 is null.

copy

public static CharArraySet copy(Set<?> set)
Returns a copy of the given set as a CharArraySet. If the given set is a CharArraySet 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 a CharArraySet the ignoreCase property will be preserved.

stringIterator

public Iterator<String> stringIterator()
returns an iterator of new allocated Strings


iterator

public Iterator<Object> iterator()
returns an iterator of new allocated Strings, this method violates the Set interface

Specified by:
iterator in interface Iterable<Object>
Specified by:
iterator in interface Collection<Object>
Specified by:
iterator in interface Set<Object>
Specified by:
iterator in class AbstractCollection<Object>


Copyright © 2000-2010 Apache Software Foundation. All Rights Reserved.