FileDocCategorySizeDatePackage
PartiallyOrderedSet.javaAPI DocJava SE 5 API5999Fri Aug 26 14:57:30 BST 2005javax.imageio.spi

PartiallyOrderedSet

public class PartiallyOrderedSet extends AbstractSet
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.
version
0.5

Fields Summary
private Map
poNodes
private Set
nodes
Constructors Summary
public PartiallyOrderedSet()
Constructs a PartiallyOrderedSet.


            
      
Methods Summary
public booleanadd(java.lang.Object o)
Adds an Object to this PartiallyOrderedSet.

        if (nodes.contains(o)) {
            return false;
        }
        
        DigraphNode node = new DigraphNode(o);
        poNodes.put(o, node);
        return true;
    
public voidclear()

        poNodes.clear();
    
public booleancontains(java.lang.Object o)

        return nodes.contains(o);
    
public booleanhasOrdering(java.lang.Object preferred, java.lang.Object other)
Returns true if an ordering exists between two nodes.

        DigraphNode preferredPONode =
            (DigraphNode)poNodes.get(preferred);
        DigraphNode otherPONode =
            (DigraphNode)poNodes.get(other);

        return preferredPONode.hasEdge(otherPONode);
    
public java.util.Iteratoriterator()
Returns an iterator over the elements contained in this collection, with an ordering that respects the orderings set by the setOrdering method.

        return new PartialOrderIterator(poNodes.values().iterator());
    
public booleanremove(java.lang.Object o)
Removes an Object from this PartiallyOrderedSet.

        DigraphNode node = (DigraphNode)poNodes.get(o);
        if (node == null) {
            return false;
        }

        poNodes.remove(o);
        node.dispose();
        return true;
    
public booleansetOrdering(java.lang.Object first, java.lang.Object second)
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.

return
true if no prior ordering existed between the nodes, falseotherwise.

        DigraphNode firstPONode =
            (DigraphNode)poNodes.get(first);
        DigraphNode secondPONode =
            (DigraphNode)poNodes.get(second);
        
        secondPONode.removeEdge(firstPONode);
        return firstPONode.addEdge(secondPONode);
    
public intsize()

        return nodes.size();
    
public booleanunsetOrdering(java.lang.Object first, java.lang.Object second)
Removes any ordering between two nodes.

return
true if a prior prefence existed between the nodes.

        DigraphNode firstPONode =
            (DigraphNode)poNodes.get(first);
        DigraphNode secondPONode =
            (DigraphNode)poNodes.get(second);

        return firstPONode.removeEdge(secondPONode) ||
            secondPONode.removeEdge(firstPONode);