Class UnmodifiableSet<T>

  • Type Parameters:
    T - the parameter type
    All Implemented Interfaces:
    java.lang.Iterable<T>, Collection<T>, IStringValueProvider, IVilGenericType, IVilType, Set<T>

    public class UnmodifiableSet<T>
    extends java.lang.Object
    implements Set<T>
    Implements an unmodifiable set wrapper. This is just a runtime type.
    Author:
    Holger Eichelberger
    • Field Detail

      • set

        private Set<T> set
    • Constructor Detail

      • UnmodifiableSet

        public UnmodifiableSet​(Set<T> set)
        Creates an unmodifiable set wrapper.
        Parameters:
        set - the set to be wrapped
    • Method Detail

      • getGenericParameterCount

        public int getGenericParameterCount()
        Description copied from interface: Collection
        Returns the number of generic parameters of T.
        Specified by:
        getGenericParameterCount in interface Collection<T>
        Returns:
        the number of generic parameter
      • getGenericParameterType

        public TypeDescriptor<?> getGenericParameterType​(int index)
        Description copied from interface: Collection
        Returns the type of the specified generic parameter of T.
        Specified by:
        getGenericParameterType in interface Collection<T>
        Parameters:
        index - the 0-based index of the generic parameter
        Returns:
        the actual type of the generic parameter
      • size

        public int size()
        Description copied from interface: Collection
        Returns the number of elements in the underlying collection.
        Specified by:
        size in interface Collection<T>
        Returns:
        the number of elements
      • allowSequenceAdjustment

        public boolean allowSequenceAdjustment()
        Description copied from interface: Collection
        Returns whether a IStringValueProvider may reorder the sequence of this collection for (test) output.
        Specified by:
        allowSequenceAdjustment in interface Collection<T>
        Returns:
        true if a value provider may reorder the sequence, false else
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Collection
        Returns whether the collection is empty.
        Specified by:
        isEmpty in interface Collection<T>
        Returns:
        true if it is empty, false else
      • isNotEmpty

        public boolean isNotEmpty()
        Description copied from interface: Collection
        Returns whether the collection is not empty (inverse of Collection.isEmpty().
        Specified by:
        isNotEmpty in interface Collection<T>
        Returns:
        false if it is empty, true else
      • includes

        public boolean includes​(T element)
        Description copied from interface: Collection
        Returns whether this collection contains a certain element.
        Specified by:
        includes in interface Collection<T>
        Parameters:
        element - the element to look for
        Returns:
        true if this collection contains element, false else
      • excludes

        public boolean excludes​(T element)
        Description copied from interface: Collection
        Returns whether this collection does not contain a certain element.
        Specified by:
        excludes in interface Collection<T>
        Parameters:
        element - the element to look for
        Returns:
        true if this collection does not contain element, true else
      • count

        public int count​(T element)
        Description copied from interface: Collection
        Returns the number of elements in this collection which are equal to element.
        Specified by:
        count in interface Collection<T>
        Parameters:
        element - the element to look for
        Returns:
        the number of equal elements in this collection
      • iterator

        public java.util.Iterator<T> iterator()
        Description copied from interface: Collection
        Returns an iterator on the individual elements of this collection.
        Specified by:
        iterator in interface Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Returns:
        the iterator
      • isEquals

        public boolean isEquals​(Collection<?> elements)
        Description copied from interface: Collection
        Returns whether this collection is equal to elements. Please note that the actual semantics, i.e., whether the elements must also be in the same sequence, depends on the actual semantics of the collection.
        Specified by:
        isEquals in interface Collection<T>
        Parameters:
        elements - the collection to be tested
        Returns:
        true if both collections are considered to be equal, false else
      • getStringValue

        public java.lang.String getStringValue​(IStringValueProvider.StringComparator comparator)
        Description copied from interface: IStringValueProvider
        Returns the string value of this object.
        Specified by:
        getStringValue in interface IStringValueProvider
        Parameters:
        comparator - if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned
        Returns:
        the string value
      • selectByKind

        public Set<T> selectByKind​(TypeDescriptor<?> type)
        Description copied from interface: Collection
        Does type selection of elements (including subtypes).
        Specified by:
        selectByKind in interface Collection<T>
        Specified by:
        selectByKind in interface Set<T>
        Parameters:
        type - the target type
        Returns:
        the selected elements (the type will be adjusted to the actual type for type)
      • selectByType

        public Set<T> selectByType​(TypeDescriptor<?> type)
        Description copied from interface: Collection
        Does type selection of elements (only the same type).
        Specified by:
        selectByType in interface Collection<T>
        Specified by:
        selectByType in interface Set<T>
        Parameters:
        type - the target type
        Returns:
        the selected elements (the type will be adjusted to the actual type for type)
      • typeReject

        public Set<T> typeReject​(TypeDescriptor<?> type)
        Description copied from interface: Collection
        Does type selection of elements not having the same type (including subtypes).
        Specified by:
        typeReject in interface Collection<T>
        Specified by:
        typeReject in interface Set<T>
        Parameters:
        type - the target type
        Returns:
        the selected elements (the type will be adjusted to the actual type for type)
      • excluding

        public Set<T> excluding​(Collection<T> set)
        Description copied from interface: Set
        Exclude the elements in set.
        Specified by:
        excluding in interface Set<T>
        Parameters:
        set - the elements to be excluded
        Returns:
        this set without the elements in set
      • including

        public Set<T> including​(Collection<T> set)
        Description copied from interface: Set
        Include the elements in set. Duplicates will not be included.
        Specified by:
        including in interface Set<T>
        Parameters:
        set - the elements to be excluded
        Returns:
        this set without the elements in set
      • add

        public T add​(T element)
        Description copied from interface: Set
        Adds an element to this set.
        Specified by:
        add in interface Set<T>
        Parameters:
        element - the element to be added
        Returns:
        element
      • remove

        public boolean remove​(T element)
        Description copied from interface: Set
        Removes the given element from this sequence.
        Specified by:
        remove in interface Set<T>
        Parameters:
        element - the element to be removed
        Returns:
        true of the element was removed, false else
      • flatten

        public Set<?> flatten()
                       throws VilException
        Description copied from interface: Collection
        Flattens this collection if needed, i.e., flatten sub-collections.
        Specified by:
        flatten in interface Collection<T>
        Specified by:
        flatten in interface Set<T>
        Returns:
        the flattened collection
        Throws:
        VilException - in case of type incompatibilities
      • select

        public Set<T> select​(ExpressionEvaluator evaluator)
                      throws VilException
        Description copied from interface: Collection
        Selects elements in this collection according to the given expression.
        Specified by:
        select in interface Collection<T>
        Specified by:
        select in interface Set<T>
        Parameters:
        evaluator - the evaluator (results must evaluate to Boolean)
        Returns:
        the selected elements
        Throws:
        VilException - in case that evaluation fails
      • reject

        public Set<T> reject​(ExpressionEvaluator evaluator)
                      throws VilException
        Description copied from interface: Collection
        Rejects elements in this collection according to the given expression.
        Specified by:
        reject in interface Collection<T>
        Specified by:
        reject in interface Set<T>
        Parameters:
        evaluator - the evaluator (results must evaluate to Boolean)
        Returns:
        the rejected elements
        Throws:
        VilException - in case that evaluation fails
      • collect

        public Set<?> collect​(ExpressionEvaluator evaluator)
                       throws VilException
        Description copied from interface: Collection
        Collects the application of evaluator to each individual element and flattens nested structures.
        Specified by:
        collect in interface Collection<T>
        Specified by:
        collect in interface Set<T>
        Parameters:
        evaluator - the evaluator (results must evaluate to Boolean)
        Returns:
        the application results
        Throws:
        VilException - in case that evaluation fails
      • apply

        public java.lang.Object apply​(ExpressionEvaluator evaluator)
                               throws VilException
        Description copied from interface: Collection
        Processes elements in this set by applying to given expression.
        Specified by:
        apply in interface Collection<T>
        Parameters:
        evaluator - the evaluator holding the iterator / expression to apply
        Returns:
        the aggregated value, null in case of no aggregation
        Throws:
        VilException - in case that selection fails
      • toSequence

        public Sequence<T> toSequence()
        Description copied from interface: Set
        Turns this set into a sequence.
        Specified by:
        toSequence in interface Set<T>
        Returns:
        the set containing the elements of this set
      • asSequence

        public Sequence<T> asSequence()
        Description copied from interface: Collection
        Turns this collection into a sequence.
        Specified by:
        asSequence in interface Collection<T>
        Returns:
        the set containing the elements of this collection
      • asSet

        public Set<T> asSet()
        Description copied from interface: Collection
        Turns this collection into a set.
        Specified by:
        asSet in interface Collection<T>
        Returns:
        the set containing the elements of this collection (excluding duplicates)
      • projectSingle

        public T projectSingle()
        Description copied from interface: Set
        In case that the sequence has exactly one element, this will be returned.
        Specified by:
        projectSingle in interface Set<T>
        Returns:
        the only element or null
      • equals

        public boolean equals​(java.lang.Object object)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toMappedSet

        public java.util.Set<T> toMappedSet()
        Description copied from interface: Set
        Converts back to a set for utilizing this with external classes.
        Specified by:
        toMappedSet in interface Set<T>
        Returns:
        the internal map
      • union

        public Set<T> union​(Set<T> set)
        Compute the union of this set and set (without duplicates).
        Specified by:
        union in interface Set<T>
        Parameters:
        set - the elements to be unified with this set
        Returns:
        the union of this set and set
      • intersection

        public Set<T> intersection​(Set<T> set)
        Returns the intersection of this set with set.
        Specified by:
        intersection in interface Set<T>
        Parameters:
        set - the elements to be unified with this set
        Returns:
        the union of this set and set
      • toString

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

        public void clear()
        Description copied from interface: Collection
        Clears this collection.
        Specified by:
        clear in interface Collection<T>
      • sum

        public T sum()
        Description copied from interface: Collection
        Returns the sum of all elements.
        Specified by:
        sum in interface Collection<T>
        Returns:
        the sum of all elements or null if the elements do not define addition
      • avg

        public java.lang.Object avg()
        Description copied from interface: Collection
        Returns the average of all elements.
        Specified by:
        avg in interface Collection<T>
        Returns:
        the average of all elements or null if the elements do not define addition or division
      • product

        public T product()
        Description copied from interface: Collection
        Returns the product of all elements.
        Specified by:
        product in interface Collection<T>
        Returns:
        the product of all elements or null if the elements do not define multiplication
      • min

        public T min()
        Description copied from interface: Collection
        Returns the minimum of all elements.
        Specified by:
        min in interface Collection<T>
        Returns:
        the minimum of all elements or null if the elements do not define the minimum operation
      • max

        public T max()
        Description copied from interface: Collection
        Returns the maximum of all elements.
        Specified by:
        max in interface Collection<T>
        Returns:
        the maximum of all elements or null if the elements do not define the maximum operation
      • includesAll

        public boolean includesAll​(Collection<?> elements)
        Description copied from interface: Collection
        Returns whether this collection contains all elements in elements.
        Specified by:
        includesAll in interface Collection<T>
        Parameters:
        elements - the elements to look for
        Returns:
        true if this collection contains all elements, false else
      • excludesAll

        public boolean excludesAll​(Collection<?> elements)
        Description copied from interface: Collection
        Returns whether this collection contains no elements from elements.
        Specified by:
        excludesAll in interface Collection<T>
        Parameters:
        elements - the elements to look for
        Returns:
        true if this collection contains none from elements, false else
      • any

        public T any​(ExpressionEvaluator evaluator)
              throws VilException
        Description copied from interface: Collection
        Returns any element complying with the evaluator.
        Specified by:
        any in interface Collection<T>
        Parameters:
        evaluator - the evaluator (results must evaluate to Boolean)
        Returns:
        one element complying with evaluator
        Throws:
        VilException - in case that application fails
      • one

        public T one​(ExpressionEvaluator evaluator)
              throws VilException
        Description copied from interface: Collection
        Returns the element complying with the evaluator if there is exactly one.
        Specified by:
        one in interface Collection<T>
        Parameters:
        evaluator - the evaluator (results must evaluate to Boolean)
        Returns:
        the element complying with evaluator
        Throws:
        VilException - in case that evaluation fails
      • exists

        public java.lang.Boolean exists​(ExpressionEvaluator evaluator)
                                 throws VilException
        Description copied from interface: Collection
        Returns whether there exists on element in the collection for which the evaluator returns true.
        Specified by:
        exists in interface Collection<T>
        Parameters:
        evaluator - the evaluator
        Returns:
        true for the exists one, false else
        Throws:
        VilException - in case that evaluation fails
      • forAll

        public java.lang.Boolean forAll​(ExpressionEvaluator evaluator)
                                 throws VilException
        Description copied from interface: Collection
        Returns whether all elements in the collection for which the evaluator returns true.
        Specified by:
        forAll in interface Collection<T>
        Parameters:
        evaluator - the evaluator
        Returns:
        true for the exists one, false else
        Throws:
        VilException - in case that evaluation fails
      • isUnique

        public java.lang.Boolean isUnique​(ExpressionEvaluator evaluator)
                                   throws VilException
        Description copied from interface: Collection
        Returns whether the evaluator returns a different result for all elements in the collection.
        Specified by:
        isUnique in interface Collection<T>
        Parameters:
        evaluator - the evaluator
        Returns:
        true if all results are different, false else
        Throws:
        VilException - in case that evaluation fails
      • difference

        public Set<T> difference​(Set<T> set)
        Description copied from interface: Set
        Calculates the difference between this and the given set.
        Specified by:
        difference in interface Set<T>
        Parameters:
        set - the set to calculate the difference for
        Returns:
        the set difference
      • symmetricDifference

        public Set<T> symmetricDifference​(Set<T> set)
        Description copied from interface: Set
        Calculates the symmetric difference between this and the given set.
        Specified by:
        symmetricDifference in interface Set<T>
        Parameters:
        set - the set to calculate the difference for
        Returns:
        the symmetric set difference
      • closure

        public Set<?> closure​(ExpressionEvaluator evaluator)
                       throws VilException
        Description copied from interface: Collection
        Calculates a transitive closure over elements provided by this collection and evaluator.
        Specified by:
        closure in interface Collection<T>
        Specified by:
        closure in interface Set<T>
        Parameters:
        evaluator - the evaluator providing the links/collections to follow
        Returns:
        the closure
        Throws:
        VilException - in case that evaluation fails
      • collectNested

        public Set<?> collectNested​(ExpressionEvaluator evaluator)
                             throws VilException
        Description copied from interface: Collection
        Collects the application of evaluator to each individual element and keeps nested structures.
        Specified by:
        collectNested in interface Collection<T>
        Specified by:
        collectNested in interface Set<T>
        Parameters:
        evaluator - the evaluator (results must evaluate to Boolean)
        Returns:
        the application results
        Throws:
        VilException - in case that evaluation fails
      • isAcyclic

        public boolean isAcyclic​(ExpressionEvaluator evaluator)
                          throws VilException
        Description copied from interface: Collection
        Returns whether the transitive closure over elements provided by this collection and evaluator does not contain a cycle.
        Specified by:
        isAcyclic in interface Collection<T>
        Parameters:
        evaluator - the evaluator providing the links/collections to follow
        Returns:
        true for cycle, false else
        Throws:
        VilException - in case that evaluation fails