E - Element typepublic class PartiallyOrderedSet<E> extends AbstractSet<E>
When you create a partially-ordered set ('poset' for short) you must
provide an PartiallyOrderedSet.Ordering that determines the order relation. The
ordering must be:
Note that not all pairs of elements are related. If is OK if e.lte(f) returns false and f.lte(e) returns false also.
In addition to the usual set methods, there are methods to determine the immediate parents and children of an element in the set, and method to find all elements which have no parents or no children (i.e. "root" and "leaf" elements).
A lattice is a special kind of poset where there is a unique top and bottom element. You can use a PartiallyOrderedSet for a lattice also. It may be helpful to add the top and bottom elements to the poset on construction.
| Modifier and Type | Class and Description |
|---|---|
private static class |
PartiallyOrderedSet.Node<E>
Holds a value, its parent nodes, and child nodes.
|
static interface |
PartiallyOrderedSet.Ordering<E>
Ordering relation.
|
private static class |
PartiallyOrderedSet.TopBottomNode<E>
Subclass of Node for top/bottom nodes.
|
| Modifier and Type | Field and Description |
|---|---|
static PartiallyOrderedSet.Ordering<ImmutableBitSet> |
BIT_SET_INCLUSION_ORDERING
Ordering that orders bit sets by inclusion.
|
private PartiallyOrderedSet.Node<E> |
bottomNode |
private com.google.common.base.Function<E,Iterable<E>> |
childFunction |
private static boolean |
DEBUG
Whether to check internal consistency all the time.
|
private Map<E,PartiallyOrderedSet.Node<E>> |
map |
private PartiallyOrderedSet.Ordering<E> |
ordering |
private com.google.common.base.Function<E,Iterable<E>> |
parentFunction |
private PartiallyOrderedSet.Node<E> |
topNode
Synthetic node to hold all nodes that have no parents.
|
| Modifier | Constructor and Description |
|---|---|
|
PartiallyOrderedSet(PartiallyOrderedSet.Ordering<E> ordering)
Creates a partially-ordered set.
|
|
PartiallyOrderedSet(PartiallyOrderedSet.Ordering<E> ordering,
Collection<E> collection)
Creates a partially-ordered set, and populates it with a given
collection.
|
|
PartiallyOrderedSet(PartiallyOrderedSet.Ordering<E> ordering,
com.google.common.base.Function<E,Iterable<E>> childFunction,
com.google.common.base.Function<E,Iterable<E>> parentFunction)
Creates a partially-ordered set with a parent-generating function.
|
private |
PartiallyOrderedSet(PartiallyOrderedSet.Ordering<E> ordering,
Map<E,PartiallyOrderedSet.Node<E>> map,
com.google.common.base.Function<E,Iterable<E>> childFunction,
com.google.common.base.Function<E,Iterable<E>> parentFunction)
Internal constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e)
Adds an element to this lattice.
|
void |
clear() |
private void |
closure(com.google.common.base.Function<E,Iterable<E>> generator,
E e,
List<E> list,
Set<E> set) |
boolean |
contains(Object o) |
private List<E> |
descendants(E e,
boolean up) |
private void |
distanceRecurse(Map<PartiallyOrderedSet.Node,Integer> distanceToRoot,
PartiallyOrderedSet.Node<E> node,
int distance) |
private Set<PartiallyOrderedSet.Node<E>> |
findChildren(E e) |
private Set<PartiallyOrderedSet.Node<E>> |
findParents(E e) |
private Set<PartiallyOrderedSet.Node<E>> |
findParentsChildren(E e,
Deque<PartiallyOrderedSet.Node<E>> ancestors,
boolean up) |
List<E> |
getAncestors(E e)
Returns a list of values in the set that are less-than a given value.
|
List<E> |
getChildren(E e)
Returns the values in this partially-ordered set that are less-than
a given value and there are no intervening values.
|
List<E> |
getChildren(E e,
boolean hypothetical)
Returns the values in this partially-ordered set that are less-than
a given value and there are no intervening values.
|
List<E> |
getDescendants(E e)
Returns a list of values in the set that are less-than a given value.
|
List<E> |
getNonChildren() |
List<E> |
getNonParents() |
List<E> |
getParents(E e)
Returns the values in this partially-ordered set that are greater-than
a given value and there are no intervening values.
|
List<E> |
getParents(E e,
boolean hypothetical)
Returns the values in this partially-ordered set that are greater-than
a given value and there are no intervening values.
|
private boolean |
isDescendantOfAny(PartiallyOrderedSet.Node<E> node,
Set<PartiallyOrderedSet.Node<E>> nodeSet)
Returns whether node's value is a descendant of any of the values in
nodeSet.
|
boolean |
isValid(boolean fail)
Checks internal consistency of this lattice.
|
Iterator<E> |
iterator() |
void |
out(StringBuilder buf) |
boolean |
remove(Object o) |
private <T> void |
replace(List<T> list,
T remove,
T add) |
int |
size() |
private static <E> com.google.common.collect.ImmutableList<E> |
strip(Iterable<PartiallyOrderedSet.Node<E>> iterable)
Converts an iterable of nodes into the list of the elements inside.
|
static <E> List<E> |
strip(List<PartiallyOrderedSet.Node<E>> list)
Returns a list, backed by a list of
PartiallyOrderedSet.Nodes, that strips
away the node and returns the element inside. |
equals, hashCode, removeAlladdAll, containsAll, isEmpty, retainAll, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitaddAll, containsAll, isEmpty, retainAll, spliterator, toArray, toArrayparallelStream, removeIf, streampublic static final PartiallyOrderedSet.Ordering<ImmutableBitSet> BIT_SET_INCLUSION_ORDERING
For example, the children of 14 (1110) are 12 (1100), 10 (1010) and 6 (0110).
private final Map<E,PartiallyOrderedSet.Node<E>> map
private final PartiallyOrderedSet.Ordering<E> ordering
private final PartiallyOrderedSet.Node<E> topNode
private final PartiallyOrderedSet.Node<E> bottomNode
private static final boolean DEBUG
public PartiallyOrderedSet(PartiallyOrderedSet.Ordering<E> ordering)
ordering - Ordering relationpublic PartiallyOrderedSet(PartiallyOrderedSet.Ordering<E> ordering, com.google.common.base.Function<E,Iterable<E>> childFunction, com.google.common.base.Function<E,Iterable<E>> parentFunction)
ordering - Ordering relationparentFunction - Function to compute parents of a node; may be nullpublic PartiallyOrderedSet(PartiallyOrderedSet.Ordering<E> ordering, Collection<E> collection)
ordering - Ordering relationcollection - Initial contents of partially-ordered setprivate PartiallyOrderedSet(PartiallyOrderedSet.Ordering<E> ordering, Map<E,PartiallyOrderedSet.Node<E>> map, com.google.common.base.Function<E,Iterable<E>> childFunction, com.google.common.base.Function<E,Iterable<E>> parentFunction)
ordering - Ordering relationmap - Map from values to nodesparentFunction - Function to compute parents of a node; may be nullpublic int size()
size in interface Collection<E>size in interface Set<E>size in class AbstractCollection<E>public boolean contains(Object o)
contains in interface Collection<E>contains in interface Set<E>contains in class AbstractCollection<E>public boolean remove(Object o)
remove in interface Collection<E>remove in interface Set<E>remove in class AbstractCollection<E>public boolean add(E e)
add in interface Collection<E>add in interface Set<E>add in class AbstractCollection<E>private boolean isDescendantOfAny(PartiallyOrderedSet.Node<E> node, Set<PartiallyOrderedSet.Node<E>> nodeSet)
node - NodenodeSet - Suspected ancestorsprivate Set<PartiallyOrderedSet.Node<E>> findChildren(E e)
private Set<PartiallyOrderedSet.Node<E>> findParents(E e)
private Set<PartiallyOrderedSet.Node<E>> findParentsChildren(E e, Deque<PartiallyOrderedSet.Node<E>> ancestors, boolean up)
private <T> void replace(List<T> list, T remove, T add)
public boolean isValid(boolean fail)
fail - Whether to throw an assertion errorprivate void distanceRecurse(Map<PartiallyOrderedSet.Node,Integer> distanceToRoot, PartiallyOrderedSet.Node<E> node, int distance)
public void out(StringBuilder buf)
public List<E> getChildren(E e)
If the value is not in this set, returns null.
e - ValuegetDescendants(E)public List<E> getChildren(E e, boolean hypothetical)
If the value is not in this set, returns null if hypothetical
is false.
e - Valuehypothetical - Whether to generate a list if value is not in the setgetDescendants(E)public List<E> getParents(E e)
If the value is not in this set, returns null.
e - ValuegetAncestors(E)public List<E> getParents(E e, boolean hypothetical)
If the value is not in this set, returns null if
hypothetical is false.
e - Valuehypothetical - Whether to generate a list if value is not in the setgetAncestors(E)private void closure(com.google.common.base.Function<E,Iterable<E>> generator, E e, List<E> list, Set<E> set)
public void clear()
clear in interface Collection<E>clear in interface Set<E>clear in class AbstractCollection<E>public List<E> getDescendants(E e)
e - Valuepublic static <E> List<E> strip(List<PartiallyOrderedSet.Node<E>> list)
PartiallyOrderedSet.Nodes, that strips
away the node and returns the element inside.E - Element typeprivate static <E> com.google.common.collect.ImmutableList<E> strip(Iterable<PartiallyOrderedSet.Node<E>> iterable)
E - Element typepublic List<E> getAncestors(E e)
e - ValueCopyright © 2012–2018 The Apache Software Foundation. All rights reserved.