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 |
---|---|
static interface |
PartiallyOrderedSet.Ordering<E>
Ordering relation.
|
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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e)
Adds an element to this lattice.
|
void |
clear() |
boolean |
contains(Object o) |
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> |
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.
|
boolean |
isValid(boolean fail)
Checks internal consistency of this lattice.
|
Iterator<E> |
iterator() |
void |
out(StringBuilder buf) |
boolean |
remove(Object o) |
int |
size() |
equals, hashCode, removeAll
addAll, containsAll, isEmpty, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, containsAll, isEmpty, retainAll, spliterator, toArray, toArray
parallelStream, removeIf, stream
public PartiallyOrderedSet(PartiallyOrderedSet.Ordering<E> ordering)
ordering
- Ordering relationpublic PartiallyOrderedSet(PartiallyOrderedSet.Ordering<E> ordering, Collection<E> collection)
ordering
- Ordering relationcollection
- Initial contents of partially-ordered setpublic 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>
public boolean isValid(boolean fail)
fail
- Whether to throw an assertion errorpublic void out(StringBuilder buf)
public List<E> getChildren(E e)
If the value is not in this set, returns the empty list.
e
- ValuegetDescendants(E)
public List<E> getParents(E e)
If the value is not in this set, returns the empty list.
e
- ValuegetAncestors(E)
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
- ValueCopyright © 2020 Hitachi Vantara. All rights reserved.