javax.imageio.spi
class: PartiallyOrderedSet [javadoc |
source]
java.lang.Object
java.util.AbstractCollection
java.util.AbstractSet
javax.imageio.spi.PartiallyOrderedSet
All Implemented Interfaces:
Set, Collection
A set of
Objects with pairwise orderings between them.
The
iterator method provides the elements in
topologically sorted order. Elements participating in a cycle
are not returned.
Unlike the
SortedSet and
SortedMap
interfaces, which require their elements to implement the
Comparable interface, this class receives ordering
information via its
setOrdering and
unsetPreference methods. This difference is due to
the fact that the relevant ordering between elements is unlikely to
be inherent in the elements themselves; rather, it is set
dynamically accoring to application policy. For example, in a
service provider registry situation, an application might allow the
user to set a preference order for service provider objects
supplied by a trusted vendor over those supplied by another.
| Methods from java.util.AbstractCollection: |
|---|
|
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString |
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from javax.imageio.spi.PartiallyOrderedSet Detail: |
public boolean add(Object o) {
if (nodes.contains(o)) {
return false;
}
DigraphNode node = new DigraphNode(o);
poNodes.put(o, node);
return true;
}
Adds an Object to this
PartiallyOrderedSet. |
public void clear() {
poNodes.clear();
}
|
public boolean contains(Object o) {
return nodes.contains(o);
}
|
public boolean hasOrdering(Object preferred,
Object other) {
DigraphNode preferredPONode =
(DigraphNode)poNodes.get(preferred);
DigraphNode otherPONode =
(DigraphNode)poNodes.get(other);
return preferredPONode.hasEdge(otherPONode);
}
Returns true if an ordering exists between two
nodes. |
public Iterator iterator() {
return new PartialOrderIterator(poNodes.values().iterator());
}
Returns an iterator over the elements contained in this
collection, with an ordering that respects the orderings set
by the setOrdering method. |
public boolean remove(Object o) {
DigraphNode node = (DigraphNode)poNodes.get(o);
if (node == null) {
return false;
}
poNodes.remove(o);
node.dispose();
return true;
}
Removes an Object from this
PartiallyOrderedSet. |
public boolean setOrdering(Object first,
Object second) {
DigraphNode firstPONode =
(DigraphNode)poNodes.get(first);
DigraphNode secondPONode =
(DigraphNode)poNodes.get(second);
secondPONode.removeEdge(firstPONode);
return firstPONode.addEdge(secondPONode);
}
Sets an ordering between two nodes. When an iterator is
requested, the first node will appear earlier in the
sequence than the second node. If a prior ordering existed
between the nodes in the opposite order, it is removed. |
public int size() {
return nodes.size();
}
|
public boolean unsetOrdering(Object first,
Object second) {
DigraphNode firstPONode =
(DigraphNode)poNodes.get(first);
DigraphNode secondPONode =
(DigraphNode)poNodes.get(second);
return firstPONode.removeEdge(secondPONode) ||
secondPONode.removeEdge(firstPONode);
}
Removes any ordering between two nodes. |