gishur.graph.core
Class WeightComparitor

java.lang.Object
  |
  +--gishur.graph.core.WeightComparitor
All Implemented Interfaces:
Comparitor

public class WeightComparitor
extends java.lang.Object
implements Comparitor

A class which compares Edges according to their weight. The weight is defined by a property of the Edges which must be given as a constructor argument. The weight may be of any primitive nubmer type or of type java.lang.Number. A default value can be set by construction which will be used when the weight property is not set at an Edge.

Version:
1.0
Author:
Christoph Sachse

Fields inherited from interface gishur.core.Comparitor
BIGGER, EQUAL, SMALLER
 
Constructor Summary
WeightComparitor(java.lang.String weightProperty, double def)
          Constructor accepting a double-value as default.
WeightComparitor(java.lang.String weightProperty, java.lang.Double def)
          Constructor accepting a Double default object which can be null (in this case, invalid weight properties will lead to an exception).
 
Method Summary
 short compare(java.lang.Object o1, java.lang.Object o2)
          Comparitor.compare(java.lang.Object, java.lang.Object)-method which accepts only two java.lang.Objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WeightComparitor

public WeightComparitor(java.lang.String weightProperty,
                        java.lang.Double def)
Constructor accepting a Double default object which can be null (in this case, invalid weight properties will lead to an exception).
Parameters:
weightProperty - the property of the Edges which provides the weight
def - the default value

WeightComparitor

public WeightComparitor(java.lang.String weightProperty,
                        double def)
Constructor accepting a double-value as default.
Parameters:
weightProperty - the property of the Edges which provides the weight
def - the default value
Method Detail

compare

public short compare(java.lang.Object o1,
                     java.lang.Object o2)
Comparitor.compare(java.lang.Object, java.lang.Object)-method which accepts only two java.lang.Objects. For this Comparitor, these objects must be of the type KeyValueHolder and their keys must be Edges. Otherwise, a CompareException will be thrown.
Specified by:
compare in interface Comparitor
Parameters:
o1,o2 - the java.lang.Objects to compare, must be KeyValueHolders with Edges as keys
Throws:
CompareException, - if this Comparitor has a bad weight type (see MSTKruskal) or if the given objects are no KeyValueHolders with Edges as keys