com.netscape.pm.model
Interface ISortable

All Known Subinterfaces:
IRole, ITransition

public interface ISortable

This is the interface used by engine objects that want to be able to determine rank amongst themselves. Objects that want to sort themselves can implement this interface and be utilized in a simple sorting routine such as quicksort:

 public void quickSort( Vector elements, int left, int right )
 {
     if( left >= right )
         return;    // fewer than two elements, do nothing

     else
     {
         swap( elements, left, (left + right) / 2 );
         int last = left;

         for( int i = left + 1; i <= right; i++ )
         {
             ISortable iElement = (ISortable) elements.elementAt( i ),
                       lElement = (ISortable) elements.elementAt( left );

             if( iElement.compareTo( lElement ) < 0 )
                 swap( elements, ++last, i );
         }

         swap( elements, left, last );
         quickSort( elements, left, last - 1 );
         quickSort( elements, last + 1, right );
     }
 }
  
 private void swap( Vector elements, int i, int j )
 {
     ISortable temp = (ISortable) elements.elementAt( i );

     elements.setElementAt( elements.elementAt( j ), i );
     elements.setElementAt( temp, j );
 } 
 


Method Summary
 int compareTo(ISortable b)
          Method to compare this sortable element with another sortable element.
 java.lang.Object getEvaluationOrder()
          Returns a string that can be used to determine the order this element has with respect to other sortable elements.
 

Method Detail

compareTo

public int compareTo(ISortable b)
Method to compare this sortable element with another sortable element. The following table lists the expected values to return:
if this < b-1
if this = b0
if this > b1
Parameters:
b - another sortable element to compare this object against
Returns:
-1 if this < b; 0 if this &eq; b; 1 if this > b.
Since:
PAE 4.0

getEvaluationOrder

public java.lang.Object getEvaluationOrder()
Returns a string that can be used to determine the order this element has with respect to other sortable elements. This method is normally used from within compareTo to provide the basis for comparing two sortable elements.

For instance, transitions are defined with an evaluation order, ranging from AA to ZZ. This method will return that evaluation order when transitions are asked to compare themselves to each other.

Returns:
the evaluation order used to compare two sortable elements.
Since:
PAE 4.0
See Also:
compareTo(com.netscape.pm.model.ISortable)