Class com.symantec.itools.vcafe.sort.PartialOrder
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.symantec.itools.vcafe.sort.PartialOrder

Object
   |
   +----com.symantec.itools.vcafe.sort.PartialOrder

public class PartialOrder
extends Object
Copyright (c) 1998 Symantec Corporation. All rights reserved. The PartialOrder class contains two static methods for doing a topological sort.

Call sort() to partially order an array of objects based on either a PartialOrder.Relation or an array of PartialOrder.Precedes.

sort() returns an array of Object such that for any two elements at indices i,j, if a[i] precedes a[j] then i < j. The input array is not modified.

If the relation is cyclic in the input array, the output array is returned partially filled. The missing array elements participate in one or more cycles.

For example, for an array of Class objects and a precedes method defined by (Class)a instanceof (Class)b && !a.equals(b), in the returned array subclasses precede base classes.

Author:
Bob Foster

Class Index

 o com.symantec.itools.vcafe.sort.PartialOrder. Precedes
 o com.symantec.itools.vcafe.sort.PartialOrder. Relation
Base class for establishing partial order relationship precedes().

Constructor Index

 o com.symantec.itools.vcafe.sort.PartialOrder()

Method Index

 o sort(Object[], PartialOrder. Relation)
Return the input array partially ordered by the specified relation.
 o sort(Object[], PartialOrder. Precedes[])
Return the input array partially ordered by the relationships specified in the precedes array.

Constructors

 o PartialOrder
public PartialOrder()

Methods

 o sort
public static java.lang.Object[] sort(Object[] input,
                                      PartialOrder.Relation relation)
Return the input array partially ordered by the specified relation.

If the array cannot be placed in a partial order (has loops) an array with less than input.length elements is returned containing only the elements that did not participate in any cycles. The caller should test the length of the returned array to determine if the sort succeeded.

Parameters:
input - an array of objects to be ordered.
relation - a class defining a precedes() method that is used to partially order the array. Note that if precedes(a[i],a[i]) the sort will fail.
 o sort
public static java.lang.Object[] sort(Object[] input,
                                      PartialOrder.Precedes[] precedes)
Return the input array partially ordered by the relationships specified in the precedes array.

If the array cannot be placed in a partial order (has loops) an array with less than input.length elements is returned containing only the elements that did not participate in any cycles. The caller should test the length of the returned array to determine if the sort succeeded.

Parameters:
input - an array of objects to be ordered.
precedes - an array of predecessor/successor pairs. The precedes array need not be exhaustive; it need only identify the immediate successors of each object.

All Packages  Class Hierarchy  This Package  Previous  Next  Index