CharArraySet (Lucene 3.6.2 API)
Keywords: org.apache.lucene.analysis.CharArraySet class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.lucene.analysis
Class CharArraySet

    java.lang.Object
      java.util.AbstractCollection<E>
          java.util.AbstractSet<Object>
              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.

You must specify the required `Version` compatibility when creating `CharArraySet`:

- As of 3.1, supplementary characters are properly lowercased.

Before 3.1 supplementary characters could not be lowercased correctly due to the lack of Unicode 4 support in JDK 1.4. To use instances of `CharArraySet` with the behavior before Lucene 3.1 pass a `Version` < 3.1 to the constructors.

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<String>`. For type safety also `stringIterator()` is provided.

Nested Class Summary
`class` | `CharArraySet.CharArraySetIterator` Deprecated. Use the standard iterator, which returns `char[]` instances.

Field Summary
`static CharArraySet` | `EMPTY_SET`

Constructor Summary
`CharArraySet(Collection<?> c, boolean ignoreCase)` Deprecated. use `CharArraySet(Version, Collection, boolean)` instead
`CharArraySet(int startSize, boolean ignoreCase)` Deprecated. use `CharArraySet(Version, int, boolean)` instead
`CharArraySet(Version matchVersion, Collection<?> c, boolean ignoreCase)` Creates a set from a Collection of objects.
`CharArraySet(Version matchVersion, 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
`void` | `clear()` Clears all entries in this 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)` Deprecated. use `copy(Version, Set)` instead.
`static CharArraySet` | `copy(Version matchVersion, Set<?> set)` Returns a copy of the given set as a `CharArraySet`.
`Iterator<Object>` | `iterator()` Returns an `CharArraySet.CharArraySetIterator` depending on the version used: if `matchVersion` ≥ 3.1, it returns `char[]` instances in this set. if `matchVersion` is 3.0 or older, it returns new allocated Strings, so this method violates the Set interface.
`int` | `size()`
`Iterator<String>` | `stringIterator()` Deprecated. Use `iterator()`, which returns `char[]` instances.
`String` | `toString()`
`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, 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.Set
`addAll, containsAll, isEmpty, remove, retainAll, toArray, toArray`

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 capacity
    `ignoreCase` - `false` if and only if the set should be case sensitive otherwise `true`.

### CharArraySet

    public CharArraySet(Version matchVersion,
                        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 set
    `ignoreCase` - `false` if and only if the set should be case sensitive otherwise `true`.

### CharArraySet

    @Deprecated
    public CharArraySet(int startSize,
                                   boolean ignoreCase)

  Deprecated. use `CharArraySet(Version, int, boolean)` instead

  Creates a set with enough capacity to hold startSize terms

  Parameters:
    `startSize` - the initial capacity
    `ignoreCase` - `false` if and only if the set should be case sensitive otherwise `true`.

### CharArraySet

    @Deprecated
    public CharArraySet(Collection<?> c,
                                   boolean ignoreCase)

  Deprecated. use `CharArraySet(Version, Collection, boolean)` instead

  Creates a set from a Collection of objects.

  Parameters:
    `c` - a collection whose elements to be placed into the set
    `ignoreCase` - `false` if and only if the set should be case sensitive otherwise `true`.

Method Detail

### clear

    public void clear()

  Clears all entries in this set. This method is supported for reusing, but not `Set.remove(java.lang.Object)`.

  Specified by:
    `clear` in interface `Collection<Object>`
  Specified by:
    `clear` in interface `Set<Object>`
  Overrides:
    `clear` in class `AbstractCollection<Object>`

### 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

### 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>`

### 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>`

### 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

    @Deprecated
    public static CharArraySet copy(Set<?> set)

  Deprecated. use `copy(Version, Set)` instead.

  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 and matchVersion property will be preserved.

### copy

    public static CharArraySet copy(Version matchVersion,
                                    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.

  Note: If you intend to create a copy of another `CharArraySet` where the `Version` of the source set differs from its copy `CharArraySet(Version, Collection, boolean)` should be used instead. The `copy(Version, Set)` will preserve the `Version` of the source set it is an instance of `CharArraySet`.

  Parameters:
    `matchVersion` - compatibility match version see Version note above for details. This argument will be ignored if the given set is a `CharArraySet`.
    `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 as well as the matchVersion will be of the given set will be preserved.

### stringIterator

    @Deprecated
    public Iterator<String> stringIterator()

  Deprecated. Use `iterator()`, which returns `char[]` instances.

  returns an iterator of new allocated Strings (an instance of `CharArraySet.CharArraySetIterator`).

### iterator

    public Iterator<Object> iterator()

  Returns an `CharArraySet.CharArraySetIterator` depending on the version used:
  - if `matchVersion` ≥ 3.1, it returns `char[]` instances in this set.
  - if `matchVersion` is 3.0 or older, it returns new allocated Strings, so this method violates the Set interface. It is kept this way for backwards compatibility, normally it should return `char[]` on `next()`

  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>`

### toString

    public String toString()

  Overrides:
    `toString` in class `AbstractCollection<Object>`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD