OSDN Git Service

1d6f44328f200076e0a27745a30dfc3d7a9acdcd
[stigmata/stigmata.git] / src / main / java / jp / sourceforge / stigmata / ComparisonPairElement.java
1 package jp.sourceforge.stigmata;
2
3 /**
4  * This class represents comparing two birthmarks.
5  * @author  Haruaki TAMADA
6  */
7 public class ComparisonPairElement{
8     private Birthmark birthmark1;
9     private Birthmark birthmark2;
10     private BirthmarkComparator comparator;
11     private double similarity;
12     private int compareCount = -1;
13
14     public ComparisonPairElement(Birthmark birthmark1, Birthmark birthmark2,
15             BirthmarkComparator comparator, BirthmarkContext context){
16         this.birthmark1 = birthmark1;
17         this.birthmark2 = birthmark2;
18         this.comparator = comparator;
19
20         if(!birthmark1.getType().equals(birthmark2.getType())){
21             throw new IllegalArgumentException("birthmark type mismatch");
22         }
23         // cached
24         similarity = comparator.compare(birthmark1, birthmark2, context);
25     }
26
27     public synchronized int getComparisonCount(){
28         // cached
29         if(compareCount < 0){
30             compareCount = comparator.getCompareCount(birthmark1, birthmark2);
31         }
32         return compareCount;
33     }
34
35     /**
36      * returns a type of birthmarks.
37      */
38     public String getType(){
39         return birthmark1.getType();
40     }
41
42     /**
43      * returns similarity between two birthmarks.
44      */
45     public double getSimilarity(){
46         return similarity;
47     }
48 }