Class PartialOrderedSet<E>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>

    public class PartialOrderedSet<E>
    extends java.util.HashSet<E>
    A Set with a partial order added to it.
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addABeforeB​(E a, E b)
      Adds the a < b to the relation.
      void addAll​(PartialOrderedSet<? extends E> set)
      Adds all elements of the other partial order set.
      boolean allowsABeforeB​(E a, E b)
      Tests if the relation allows for a < b.
      void clear()  
      boolean equals​(java.lang.Object obj)  
      java.util.List<E> getLinearization()
      Getter for a linearization of the partial order set.
      java.util.Map<E,​java.util.Set<E>> getOrder()
      Returns the map containing the forward dependencies defining the order.
      java.util.List<E> getTotalOrder()
      Creates a total order of the elements stored in this PartialOrderedSet.
      java.util.Set<E> getTransitiveClosure​(E e)
      Gets the transitive closure of an element under this relation.
      java.util.Set<E> getTransitiveClosure​(java.util.Set<E> subSet)
      Gets the transitive closure of a set.
      int hashCode()  
      boolean isADirectlyBeforeB​(E a, E b)
      Tests whether a < b is directly, not just transitively, specified by the order.
      boolean isReflexive()
      Tests whether the relation is reflexive.
      java.util.Iterator<E> iterator()  
      void merge​(PartialOrderedSet<? extends E> set)
      If the collection is a PartialOrderedSet, the order will also be added.
      boolean remove​(java.lang.Object e)  
      boolean removeAll​(java.util.Collection<?> c)  
      boolean removeIf​(java.util.function.Predicate<? super E> filter)  
      void requireABeforeB​(E a, E b)
      Require that A is before b.
      boolean retainAll​(java.util.Collection<?> c)  
      java.lang.String toString()  
      • Methods inherited from class java.util.HashSet

        add, clone, contains, isEmpty, size, spliterator
      • Methods inherited from class java.util.AbstractCollection

        addAll, containsAll, toArray, toArray
      • Methods inherited from class java.lang.Object

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

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

        forEach
      • Methods inherited from interface java.util.Set

        addAll, containsAll, toArray, toArray
    • Constructor Detail

      • PartialOrderedSet

        public PartialOrderedSet​(PartialOrderedSet<E> original)
        Creates a new partial ordered set with the same elements as original and the same order.
        Parameters:
        original - The PartialOrderedSet to copy.
      • PartialOrderedSet

        public PartialOrderedSet()
        Creates a new empty PartialOrderedSet.
    • Method Detail

      • addABeforeB

        public void addABeforeB​(E a,
                                E b)
        Adds the a < b to the relation.
        Parameters:
        a - the smaller element
        b - the bigger element
        Throws:
        java.lang.IllegalStateException - if b < a is in the relation.
      • requireABeforeB

        public void requireABeforeB​(E a,
                                    E b)
        Require that A is before b.
        Parameters:
        a - The A which is to be tested.
        b - The B which is to be tested.
      • allowsABeforeB

        public boolean allowsABeforeB​(E a,
                                      E b)
        Tests if the relation allows for a < b.
        Parameters:
        a - The element that is tested to be allowed before b.
        b - The element that is tested to be allowed after a.
        Returns:
      • getOrder

        public java.util.Map<E,​java.util.Set<E>> getOrder()
        Returns the map containing the forward dependencies defining the order.
        Returns:
        The map containing the order.
      • isADirectlyBeforeB

        public boolean isADirectlyBeforeB​(E a,
                                          E b)
        Tests whether a < b is directly, not just transitively, specified by the order.
        Parameters:
        a - The first element.
        b - The second element.
        Returns:
        Whether the order specifies directly, that a < b has to hold.
      • getTransitiveClosure

        public java.util.Set<E> getTransitiveClosure​(E e)
        Gets the transitive closure of an element under this relation.
        Parameters:
        e - The element of which the transitive closure is asked for.
        Returns:
        The transitive closure of e.
        Throws:
        java.lang.NullPointerException - if e is null.
      • getTransitiveClosure

        public java.util.Set<E> getTransitiveClosure​(java.util.Set<E> subSet)
        Gets the transitive closure of a set.
        Parameters:
        subSet - The set of which the transitive closure is asked for.
        Returns:
        The transitive closure of subSet.
        Throws:
        java.lang.NullPointerException - if subSet is null.
      • isReflexive

        public boolean isReflexive()
        Tests whether the relation is reflexive.
        Returns:
        Whether the relation is reflexive.
      • getTotalOrder

        public java.util.List<E> getTotalOrder()
        Creates a total order of the elements stored in this PartialOrderedSet. The order is created by iterating over all elements in the set and inserting each element in the list at the position of the element with the currently smallest index that has to be after the current element. If no elements needs to be after the current element, it is appended to the end. The runtime is O(n²).
        Returns:
        A total ordering of the elements in this PartialOrderedSet.
      • merge

        public void merge​(PartialOrderedSet<? extends E> set)
        If the collection is a PartialOrderedSet, the order will also be added. If the that would destroy asymmetry an IllegalStateException will be thrown.
        Throws:
        java.lang.IllegalStateException - if adding the order of another PartialOrderedSet would destroy asymmetry.
      • addAll

        public void addAll​(PartialOrderedSet<? extends E> set)
        Adds all elements of the other partial order set.
        Parameters:
        set - The set to be added to this partial-order set.
      • toString

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

        public java.util.List<E> getLinearization()
        Getter for a linearization of the partial order set.
        Returns:
        A list representing a linearization of the partial order set.
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.Set<E>
        Overrides:
        iterator in class java.util.HashSet<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.Set<E>
        Overrides:
        clear in class java.util.HashSet<E>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<E>
        Specified by:
        removeAll in interface java.util.Set<E>
        Overrides:
        removeAll in class java.util.AbstractSet<E>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<E>
        Specified by:
        retainAll in interface java.util.Set<E>
        Overrides:
        retainAll in class java.util.AbstractCollection<E>
      • removeIf

        public boolean removeIf​(java.util.function.Predicate<? super E> filter)
      • remove

        public boolean remove​(java.lang.Object e)
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.Set<E>
        Overrides:
        remove in class java.util.HashSet<E>
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<E>
        Specified by:
        hashCode in interface java.util.Set<E>
        Overrides:
        hashCode in class java.util.AbstractSet<E>
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Collection<E>
        Specified by:
        equals in interface java.util.Set<E>
        Overrides:
        equals in class java.util.AbstractSet<E>