org.oddjob.beancmpr.comparers
Class NumericComparer

java.lang.Object
  extended by org.oddjob.beancmpr.comparers.NumericComparer
All Implemented Interfaces:
Comparer<Number>

public class NumericComparer
extends Object
implements Comparer<Number>

A Comparer for numbers that supports tolerances and provides the comparison as a difference between the numbers and as a percentage change between numbers.

The change is considered as going from x to y. If x is 200 and y is 190, the delta is -10, and the percentage chnage is 5%.

Two numbers are only considered different if their delta is more the given tolerance or more. The tolerance may be specified as either a delta tolerance number that two numbers must differ more than, or a minimum percentage change that the two number must exceed.

The comparison is only unequal if the difference between the two numbers is greater than both tolerances. Both tolerances default to zero.

If either or both input number is null, the result of the compare is null.

Author:
Rob

Constructor Summary
NumericComparer()
           
 
Method Summary
 NumericComparison compare(Number x, Number y)
          Compare two things.
 String getDeltaFormat()
           
 double getDeltaTolerance()
           
 String getPercentageFormat()
           
 double getPercentageTolerance()
           
 Class<Number> getType()
          The type of the things.
 void setDeltaFormat(String deltaFormat)
           
 void setDeltaTolerance(double deltaTolerance)
           
 void setPercentageFormat(String percentageFormat)
           
 void setPercentageTolerance(double percentageTolerance)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumericComparer

public NumericComparer()
Method Detail

compare

public NumericComparison compare(Number x,
                                 Number y)
Description copied from interface: Comparer
Compare two things.

Specified by:
compare in interface Comparer<Number>
Parameters:
x - One thing.
y - The other thing.
Returns:
A Comparison. The may be null if either or both of x and y is null.

getType

public Class<Number> getType()
Description copied from interface: Comparer
The type of the things.

Note that we would have liked the return type to be Class<T> but we could not then have had a Comparer<Iterable<MatchableGroup>> because it's not possible to return a type of Class<Iterable<MatchableGroup>> in Java. If there is a solution to this then please let us know.

Specified by:
getType in interface Comparer<Number>
Returns:
The type. Must not be null.

getDeltaTolerance

public double getDeltaTolerance()

setDeltaTolerance

public void setDeltaTolerance(double deltaTolerance)

getPercentageTolerance

public double getPercentageTolerance()

setPercentageTolerance

public void setPercentageTolerance(double percentageTolerance)

getDeltaFormat

public String getDeltaFormat()

setDeltaFormat

public void setDeltaFormat(String deltaFormat)

getPercentageFormat

public String getPercentageFormat()

setPercentageFormat

public void setPercentageFormat(String percentageFormat)

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013. All Rights Reserved.