edu.iastate.metnet.metaomgraph
Class SortableData

java.lang.Object
  extended by java.lang.Number
      extended by edu.iastate.metnet.metaomgraph.SortableData
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class SortableData
extends java.lang.Number
implements java.lang.Comparable

Class for sorting data in ascending or descending order while retaining information about the data's original order. When sorting in ascending order, the compareTo() method behaves normally (returns 1 when this value is greater than the compare-to value). When sorting descending, however, it works backwards (that is, returns 1 when this value is less than the compare-to value). This way, Arrays.sort() will sort an array of this data in the requested order. Furthermore, this class can be sorted by the data or by the original index by calling the setSortByData() method. If setSortByData(true) is called, then

See Also:
Serialized Form

Constructor Summary
SortableData(double value, int index)
          Constructs a new object that sorts by data in ascending order.
SortableData(double value, int index, boolean ascending)
          Constructs a new object that sorts by data.
SortableData(double value, int index, boolean ascending, boolean sortByData)
          Constructor.
 
Method Summary
 int compareTo(java.lang.Object arg0)
           
 double doubleValue()
           
 float floatValue()
           
 int getIndex()
           
 double getValue()
           
 double getValueToCompare()
          Returns the data value if sortByData is true.
 int intValue()
           
 boolean isAscending()
           
 boolean isSortByData()
           
 long longValue()
           
 void setAscending(boolean ascending)
          Determines whether to sort in ascending or descending order
 void setIndex(int index)
          Sets this object's index
 void setSortByData(boolean sortByData)
          Sets whether to sort by data or by index.
 void setValue(double value)
          Sets a new data value for this object
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortableData

public SortableData(double value,
                    int index)
Constructs a new object that sorts by data in ascending order.

Parameters:
value - The data
index - The original index of the data

SortableData

public SortableData(double value,
                    int index,
                    boolean ascending)
Constructs a new object that sorts by data.

Parameters:
value - The data
index - The original index of the data
ascending - When true, Arrays.sort() will sort this data in ascending order. When false, Arrays.sort() will sort in descending order.

SortableData

public SortableData(double value,
                    int index,
                    boolean ascending,
                    boolean sortByData)
Constructor.

Parameters:
value - The data
index - The original index of the data
ascending - When true, Arrays.sort() will sort in ascending order. When false, Arrays.sort() will sort in descending order.
sortByData - When true, Arrays.sort() will sort this object by its data value. When false, Arrays.sort() will sort by the index.
Method Detail

compareTo

public int compareTo(java.lang.Object arg0)
Specified by:
compareTo in interface java.lang.Comparable

getValueToCompare

public double getValueToCompare()
Returns the data value if sortByData is true. Returns the index otherwise.

Returns:
The value to be used for comparisons

doubleValue

public double doubleValue()
Specified by:
doubleValue in class java.lang.Number

floatValue

public float floatValue()
Specified by:
floatValue in class java.lang.Number

intValue

public int intValue()
Specified by:
intValue in class java.lang.Number

longValue

public long longValue()
Specified by:
longValue in class java.lang.Number

isAscending

public boolean isAscending()
Returns:
true if this object will be sorted in ascending order, false if descending order.

setAscending

public void setAscending(boolean ascending)
Determines whether to sort in ascending or descending order

Parameters:
ascending - If true, future sorts will be done in ascending order. If false, future sorts will be done in descending order.

getIndex

public int getIndex()
Returns:
This object's index

setIndex

public void setIndex(int index)
Sets this object's index

Parameters:
index - The new index

isSortByData

public boolean isSortByData()
Returns:
True if this object will sort by data value, false if it will sort by index

setSortByData

public void setSortByData(boolean sortByData)
Sets whether to sort by data or by index. Sorts by data by default.

Parameters:
sortByData -

getValue

public double getValue()
Returns:
This object's data value

setValue

public void setValue(double value)
Sets a new data value for this object

Parameters:
value - The new data value