Package ai.libs.jaicore.basic.sets
Class PartialOrderedSet<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- java.util.HashSet<E>
-
- ai.libs.jaicore.basic.sets.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>ASetwith a partial order added to it.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PartialOrderedSet()Creates a new emptyPartialOrderedSet.PartialOrderedSet(PartialOrderedSet<E> original)Creates a new partial ordered set with the same elements asoriginaland the same order.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddABeforeB(E a, E b)Adds the a < b to the relation.voidaddAll(PartialOrderedSet<? extends E> set)Adds all elements of the other partial order set.booleanallowsABeforeB(E a, E b)Tests if the relation allows for a < b.voidclear()booleanequals(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 thisPartialOrderedSet.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.inthashCode()booleanisADirectlyBeforeB(E a, E b)Tests whether a < b is directly, not just transitively, specified by the order.booleanisReflexive()Tests whether the relation is reflexive.java.util.Iterator<E>iterator()voidmerge(PartialOrderedSet<? extends E> set)If the collection is aPartialOrderedSet, the order will also be added.booleanremove(java.lang.Object e)booleanremoveAll(java.util.Collection<?> c)booleanremoveIf(java.util.function.Predicate<? super E> filter)voidrequireABeforeB(E a, E b)Require that A is before b.booleanretainAll(java.util.Collection<?> c)java.lang.StringtoString()
-
-
-
Constructor Detail
-
PartialOrderedSet
public PartialOrderedSet(PartialOrderedSet<E> original)
Creates a new partial ordered set with the same elements asoriginaland the same order.- Parameters:
original- ThePartialOrderedSetto copy.
-
PartialOrderedSet
public PartialOrderedSet()
Creates a new emptyPartialOrderedSet.
-
-
Method Detail
-
addABeforeB
public void addABeforeB(E a, E b)
Adds the a < b to the relation.- Parameters:
a- the smaller elementb- 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 thisPartialOrderedSet. 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 aPartialOrderedSet, the order will also be added. If the that would destroy asymmetry anIllegalStateExceptionwill be thrown.- Throws:
java.lang.IllegalStateException- if adding the order of anotherPartialOrderedSetwould 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:
toStringin classjava.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()
-
clear
public void clear()
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super E> filter)
-
remove
public boolean remove(java.lang.Object e)
-
hashCode
public int hashCode()
-
-