Class 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 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<char[]>.

    • Constructor Summary

      Constructors 
      Constructor Description
      CharArraySet​(Version matchVersion, int startSize, boolean ignoreCase)
      Create set with enough capacity to hold startSize terms
      CharArraySet​(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
      boolean add​(char[] text)
      Add this char[] directly to the set.
      boolean add​(java.lang.CharSequence text)
      Add this CharSequence into the set
      boolean add​(java.lang.Object o)  
      boolean add​(java.lang.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​(java.lang.CharSequence cs)
      true if the CharSequence is in the set
      boolean contains​(java.lang.Object o)  
      static CharArraySet copy​(Version matchVersion, java.util.Set<?> set)
      Returns a copy of the given set as a CharArraySet.
      java.util.Iterator<java.lang.Object> iterator()
      Returns an Iterator for char[] instances in this set.
      int size()  
      java.lang.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

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        addAll, containsAll, isEmpty, remove, retainAll, spliterator, toArray, toArray
    • 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,
                            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 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 java.util.Collection<java.lang.Object>
        Specified by:
        clear in interface java.util.Set<java.lang.Object>
        Overrides:
        clear in class java.util.AbstractCollection<java.lang.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​(java.lang.CharSequence cs)
        true if the CharSequence is in the set
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<java.lang.Object>
        Specified by:
        contains in interface java.util.Set<java.lang.Object>
        Overrides:
        contains in class java.util.AbstractCollection<java.lang.Object>
      • add

        public boolean add​(java.lang.Object o)
        Specified by:
        add in interface java.util.Collection<java.lang.Object>
        Specified by:
        add in interface java.util.Set<java.lang.Object>
        Overrides:
        add in class java.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:
        size in interface java.util.Collection<java.lang.Object>
        Specified by:
        size in interface java.util.Set<java.lang.Object>
        Specified by:
        size in class java.util.AbstractCollection<java.lang.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:
        java.lang.NullPointerException - if the given set is null.
      • iterator

        public java.util.Iterator<java.lang.Object> iterator()
        Returns an Iterator for char[] instances in this set.
        Specified by:
        iterator in interface java.util.Collection<java.lang.Object>
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Object>
        Specified by:
        iterator in interface java.util.Set<java.lang.Object>
        Specified by:
        iterator in class java.util.AbstractCollection<java.lang.Object>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractCollection<java.lang.Object>