Class CaseInsensitiveSet

  • All Implemented Interfaces:
    Iterable<String>, Collection<String>, Set<String>

    public class CaseInsensitiveSet
    extends SetDecorator<String>
    An implementation of a set whose values are case-insensitive strings. All operations match values in a case-insensitive manner. The original cases of values are retained, so the iterator() method for example returns the originally values.

    Note: The behavior of this class is undefined when wrapping a set that has keys that would result in duplicate case-insensitive values.

    • Constructor Detail

      • CaseInsensitiveSet

        public CaseInsensitiveSet()
        Constructs a new empty case-insensitive set. The backing set is a new HashSet with default initial capacity and load factor.
      • CaseInsensitiveSet

        public CaseInsensitiveSet​(Collection<String> c)
        Constructs a new case-insensitive set containing the elements in the specified collection. The HashSet is created with default load factor and an initial capacity sufficient to contain the elements in the specified collection.
        Parameters:
        c - the collection whose elements are to be placed into this set.
        Throws:
        NullPointerException - if the specified collection is null.
      • CaseInsensitiveSet

        public CaseInsensitiveSet​(int initialCapacity,
                                  float loadFactor)
        Constructs a new, empty case-insensitive set; the backing HashSet instance has the specified initial capacity and the specified load factor.
        Parameters:
        initialCapacity - the initial capacity of the hash set.
        loadFactor - the load factor of the hash set.
        Throws:
        IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive.
      • CaseInsensitiveSet

        public CaseInsensitiveSet​(int initialCapacity)
        Constructs a new, empty case-insensitive set; the backing HashSet instance has the specified initial capacity and default load factor.
        Parameters:
        initialCapacity - the initial capacity of the hash set.
        Throws:
        IllegalArgumentException - if the initial capacity is less than zero.
    • Method Detail

      • contains

        public boolean contains​(Object o)
        Description copied from class: SetDecorator
        Returns true if the set contains the specified element.
        Specified by:
        contains in interface Collection<String>
        Specified by:
        contains in interface Set<String>
        Overrides:
        contains in class SetDecorator<String>
        Parameters:
        o - element whose presence in the set is to be tested.
        Returns:
        true if the set contains the specified element.
      • add

        public boolean add​(String e)
        Description copied from class: SetDecorator
        Adds the specified element to the set if it is not already present (optional operation).
        Specified by:
        add in interface Collection<String>
        Specified by:
        add in interface Set<String>
        Overrides:
        add in class SetDecorator<String>
        Parameters:
        e - element to be added to the set.
        Returns:
        true if the set did not already contain the specified element.
      • remove

        public boolean remove​(Object o)
        Description copied from class: SetDecorator
        Removes the specified element from the set if it is present (optional operation).
        Specified by:
        remove in interface Collection<String>
        Specified by:
        remove in interface Set<String>
        Overrides:
        remove in class SetDecorator<String>
        Parameters:
        o - object to be removed from the set, if present.
        Returns:
        true if the set contained the specified element.
      • containsAll

        public boolean containsAll​(Collection<?> c)
        Description copied from class: SetDecorator
        Returns true if the set contains all of the elements of the specified collection.
        Specified by:
        containsAll in interface Collection<String>
        Specified by:
        containsAll in interface Set<String>
        Overrides:
        containsAll in class SetDecorator<String>
        Parameters:
        c - collection to be checked for containment in the set.
        Returns:
        true if the set contains all of the elements of the specified collection.
      • addAll

        public boolean addAll​(Collection<? extends String> c)
        Description copied from class: SetDecorator
        Adds all of the elements in the specified collection to the set if they're not already present (optional operation).
        Specified by:
        addAll in interface Collection<String>
        Specified by:
        addAll in interface Set<String>
        Overrides:
        addAll in class SetDecorator<String>
        Parameters:
        c - collection containing elements to be added to the set.
        Returns:
        true if the set changed as a result of the call.
      • retainAll

        public boolean retainAll​(Collection<?> c)
        Description copied from class: SetDecorator
        Retains only the elements in the set that are contained in the specified collection (optional operation).
        Specified by:
        retainAll in interface Collection<String>
        Specified by:
        retainAll in interface Set<String>
        Overrides:
        retainAll in class SetDecorator<String>
        Parameters:
        c - collection containing elements to be retained in the set.
        Returns:
        true if the set changed as a result of the call.
      • removeAll

        public boolean removeAll​(Collection<?> c)
        Description copied from class: SetDecorator
        Removes from the set all of its elements that are contained in the specified collection (optional operation).
        Specified by:
        removeAll in interface Collection<String>
        Specified by:
        removeAll in interface Set<String>
        Overrides:
        removeAll in class SetDecorator<String>
        Parameters:
        c - collection containing elements to be removed from the set.
        Returns:
        true if the set changed as a result of the call.