Class StringSet

  • All Implemented Interfaces:
    java.lang.Comparable<StringSet>, java.lang.Iterable<java.lang.String>, java.util.Collection<java.lang.String>, java.util.Set<java.lang.String>

    public final class StringSet
    extends java.lang.Object
    implements java.util.Set<java.lang.String>, java.lang.Comparable<StringSet>
    Immutable Set<String> that never contains null to use as a cell type. Some of the constructors taking lambdas allow to construct the StringSet without first constructing a collection that is copied again for immutability.
    Author:
    Gisa Meier
    • Constructor Summary

      Constructors 
      Constructor Description
      StringSet​(java.util.Collection<java.lang.String> collection)
      Creates a new immutable string set by copying the given collection or, in case it is null, creating an empty set.
      StringSet​(java.util.Collection<java.lang.String> collection, java.util.function.UnaryOperator<java.lang.String> preprocessor)
      Creates a new string set by applying the preprocessor to every element of the collection.
      StringSet​(java.util.function.IntFunction<java.lang.String> supplier, int limit)
      Applies the supplier to the indices from 0 (inclusive) to limit (exclusive) and adds the result to the string set if it is not null.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(java.lang.String s)  
      boolean addAll​(java.util.Collection<? extends java.lang.String> c)  
      void clear()  
      int compareTo​(StringSet otherSet)  
      boolean contains​(java.lang.Object o)  
      boolean containsAll​(java.util.Collection<?> c)  
      boolean equals​(java.lang.Object o)  
      void forEach​(java.util.function.Consumer<? super java.lang.String> action)  
      int hashCode()  
      boolean isEmpty()  
      java.util.Iterator<java.lang.String> iterator()  
      java.util.stream.Stream<java.lang.String> parallelStream()  
      boolean remove​(java.lang.Object o)  
      boolean removeAll​(java.util.Collection<?> c)  
      boolean removeIf​(java.util.function.Predicate<? super java.lang.String> filter)  
      boolean retainAll​(java.util.Collection<?> c)  
      int size()  
      java.util.Spliterator<java.lang.String> spliterator()  
      java.util.stream.Stream<java.lang.String> stream()  
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] a)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

        toArray
    • Constructor Detail

      • StringSet

        public StringSet​(java.util.Collection<java.lang.String> collection)
        Creates a new immutable string set by copying the given collection or, in case it is null, creating an empty set. null entries are removed.
        Parameters:
        collection - the collection to copy, can be null
      • StringSet

        public StringSet​(java.util.Collection<java.lang.String> collection,
                         java.util.function.UnaryOperator<java.lang.String> preprocessor)
        Creates a new string set by applying the preprocessor to every element of the collection. Preprocessed elements are only added if they are not null. If the collection is null an empty set is created. If the preprocessor is null no preprocessing takes place.
        Parameters:
        collection - the collection containing the elements to add after preprocessing
        preprocessor - the function to apply to the element before adding them
      • StringSet

        public StringSet​(java.util.function.IntFunction<java.lang.String> supplier,
                         int limit)
        Applies the supplier to the indices from 0 (inclusive) to limit (exclusive) and adds the result to the string set if it is not null.
        Parameters:
        supplier - the function creating an element given an index
        limit - the limit until which to apply the supplier (not inclusive)
    • Method Detail

      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<java.lang.String>
        Specified by:
        size in interface java.util.Set<java.lang.String>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<java.lang.String>
        Specified by:
        isEmpty in interface java.util.Set<java.lang.String>
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<java.lang.String>
        Specified by:
        contains in interface java.util.Set<java.lang.String>
      • iterator

        public java.util.Iterator<java.lang.String> iterator()
        Specified by:
        iterator in interface java.util.Collection<java.lang.String>
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.String>
        Specified by:
        iterator in interface java.util.Set<java.lang.String>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<java.lang.String>
        Specified by:
        toArray in interface java.util.Set<java.lang.String>
      • toArray

        public <T> T[] toArray​(T[] a)
        Specified by:
        toArray in interface java.util.Collection<java.lang.String>
        Specified by:
        toArray in interface java.util.Set<java.lang.String>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<java.lang.String>
        Specified by:
        containsAll in interface java.util.Set<java.lang.String>
      • spliterator

        public java.util.Spliterator<java.lang.String> spliterator()
        Specified by:
        spliterator in interface java.util.Collection<java.lang.String>
        Specified by:
        spliterator in interface java.lang.Iterable<java.lang.String>
        Specified by:
        spliterator in interface java.util.Set<java.lang.String>
      • stream

        public java.util.stream.Stream<java.lang.String> stream()
        Specified by:
        stream in interface java.util.Collection<java.lang.String>
      • parallelStream

        public java.util.stream.Stream<java.lang.String> parallelStream()
        Specified by:
        parallelStream in interface java.util.Collection<java.lang.String>
      • forEach

        public void forEach​(java.util.function.Consumer<? super java.lang.String> action)
        Specified by:
        forEach in interface java.lang.Iterable<java.lang.String>
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Collection<java.lang.String>
        Specified by:
        equals in interface java.util.Set<java.lang.String>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<java.lang.String>
        Specified by:
        hashCode in interface java.util.Set<java.lang.String>
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(StringSet otherSet)
        Specified by:
        compareTo in interface java.lang.Comparable<StringSet>
      • addAll

        public boolean addAll​(java.util.Collection<? extends java.lang.String> c)
        Specified by:
        addAll in interface java.util.Collection<java.lang.String>
        Specified by:
        addAll in interface java.util.Set<java.lang.String>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<java.lang.String>
        Specified by:
        retainAll in interface java.util.Set<java.lang.String>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<java.lang.String>
        Specified by:
        removeAll in interface java.util.Set<java.lang.String>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<java.lang.String>
        Specified by:
        clear in interface java.util.Set<java.lang.String>
      • add

        public boolean add​(java.lang.String s)
        Specified by:
        add in interface java.util.Collection<java.lang.String>
        Specified by:
        add in interface java.util.Set<java.lang.String>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<java.lang.String>
        Specified by:
        remove in interface java.util.Set<java.lang.String>
      • removeIf

        public boolean removeIf​(java.util.function.Predicate<? super java.lang.String> filter)
        Specified by:
        removeIf in interface java.util.Collection<java.lang.String>