org.knime.core.data
Class DataValueComparator

java.lang.Object
  extended by org.knime.core.data.DataValueComparator
All Implemented Interfaces:
Comparator<DataCell>
Direct Known Subclasses:
ComplexNumberValueComparator, DateAndTimeComparator, DoubleValueComparator, FuzzyIntervalValueComparator, FuzzyNumberValueComparator, GeneralDataValueComparator, IntervalValueComparator, IntValueComparator, LongValueComparator, StringValueComparator, TimestampValue.TimestampValueComparator

public abstract class DataValueComparator
extends Object
implements Comparator<DataCell>

The comparator used to compare two DataValue objects. An instance of this class is returned by each DataValue.UtilityFactory implementation. Implementations can safely assume that objects passed to the compareDataValues(DataValue, DataValue) method support a type cast to that type of the DataValue returning this comparator.

Note: this comparator imposes orderings that are inconsistent with equals. That is, the return value zero is not equivalent to equals returning true, it rather says "don't know". Meaning, if two DataValues cannot be compared (because they represent completely different value types) the comparator will return zero - and equals will return false.)

Author:
Michael Berthold, University of Konstanz
See Also:
DataValue.UtilityFactory.getComparator()

Constructor Summary
protected DataValueComparator()
          Create a new DataValue comparator.
 
Method Summary
 int compare(DataCell c1, DataCell c2)
          This final implementation checks and handles DataCells representing missing values, before it delegates the actual comparison to the derived class, by calling compareDataValues(DataValue, DataValue).
protected abstract  int compareDataValues(DataValue v1, DataValue v2)
          Do not call this function, rather call the compare(DataCell, DataCell) method, which handles missing cells.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

DataValueComparator

protected DataValueComparator()
Create a new DataValue comparator. This constructor does nothing.

Method Detail

compare

public final int compare(DataCell c1,
                         DataCell c2)
This final implementation checks and handles DataCells representing missing values, before it delegates the actual comparison to the derived class, by calling compareDataValues(DataValue, DataValue). Missing cells are considered to be smaller than any other non-missing DataCell, and two missing cells are not comparable (returns 0). Note: return value 0 is not equivalent to c1 equals c2, rather they are not comparable at all.

Specified by:
compare in interface Comparator<DataCell>
Parameters:
c1 - the first DataCell to compare the other with
c2 - the other DataCell to compare the first with
Returns:
a negative number if c1 is smaller than c2, a positive number if c1 is larger than c2, otherwise zero
Throws:
NullPointerException - if any of the objects is null
See Also:
Comparator.compare(java.lang.Object, java.lang.Object), compareDataValues(DataValue, DataValue)

compareDataValues

protected abstract int compareDataValues(DataValue v1,
                                         DataValue v2)
Do not call this function, rather call the compare(DataCell, DataCell) method, which handles missing cells. The derived class should compare the two passed DataValues. It can be safely assumed that both values are castable to the specific type of the DataValue that returned this comparator.

Parameters:
v1 - the first DataValue to compare the other with
v2 - the other DataValue to compare the first with
Returns:
return -1 if v1 is smaller than v2, +1 if v1 is larger than v2, 0 otherwise


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.