org.unitils.reflectionassert.util
Class MatchingScoreCalculator

java.lang.Object
  extended by org.unitils.reflectionassert.util.MatchingScoreCalculator

public class MatchingScoreCalculator
extends Object

A utility class to be able to calculate a score of how well 2 elements match. This enables us to find the best matching differences out of all element differences in an unordered collection difference.

Author:
Tim Ducheyne, Filip Neven

Nested Class Summary
protected  class MatchingScoreCalculator.MatchingScoreVisitor
          The visitor for visiting the difference tree.
 
Field Summary
protected  Map<Difference,Integer> cachedMatchingScores
          Cache for matching scores
protected  MatchingScoreCalculator.MatchingScoreVisitor matchingScoreVisitor
          The visitor for visiting the difference tree
 
Constructor Summary
MatchingScoreCalculator()
           
 
Method Summary
 int calculateMatchingScore(Difference difference)
          Gets the matching score for the given difference.
protected  int getMatchingScore(CollectionDifference collectionDifference)
          Gets the matching score for a collection difference.
protected  int getMatchingScore(Difference difference)
          Gets the matching score for a simple difference.
protected  int getMatchingScore(MapDifference mapDifference)
          Gets the matching score for a map difference.
protected  int getMatchingScore(ObjectDifference objectDifference)
          Gets the matching score for an object difference.
protected  int getMatchingScore(UnorderedCollectionDifference unorderedCollectionDifference)
          Gets the matching score for an unordered collection difference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

matchingScoreVisitor

protected MatchingScoreCalculator.MatchingScoreVisitor matchingScoreVisitor
The visitor for visiting the difference tree


cachedMatchingScores

protected Map<Difference,Integer> cachedMatchingScores
Cache for matching scores

Constructor Detail

MatchingScoreCalculator

public MatchingScoreCalculator()
Method Detail

calculateMatchingScore

public int calculateMatchingScore(Difference difference)
Gets the matching score for the given difference.

Parameters:
difference - The difference
Returns:
The score

getMatchingScore

protected int getMatchingScore(Difference difference)
Gets the matching score for a simple difference. This will return 0 in case both objects are of the same type. If both objects are of a different type, they are less likely to be a best match, so 5 is returned.

Parameters:
difference - The difference, not null
Returns:
The score

getMatchingScore

protected int getMatchingScore(ObjectDifference objectDifference)
Gets the matching score for an object difference. Returns the nr of field differences.

Parameters:
objectDifference - The difference, not null
Returns:
The score

getMatchingScore

protected int getMatchingScore(MapDifference mapDifference)
Gets the matching score for a map difference. Returns the nr of value differences.

Parameters:
mapDifference - The difference, not null
Returns:
The score

getMatchingScore

protected int getMatchingScore(CollectionDifference collectionDifference)
Gets the matching score for a collection difference. Returns the nr of element differences.

Parameters:
collectionDifference - The difference, not null
Returns:
The score

getMatchingScore

protected int getMatchingScore(UnorderedCollectionDifference unorderedCollectionDifference)
Gets the matching score for an unordered collection difference. Returns the sum of the matching scores of the best matches.

Parameters:
unorderedCollectionDifference - The difference, not null
Returns:
The score


Copyright © 2011. All Rights Reserved.