OSDN Git Service

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