1 package jp.naist.se.stigmata;
\r
8 import java.util.ArrayList;
\r
9 import java.util.HashMap;
\r
10 import java.util.Iterator;
\r
11 import java.util.List;
\r
12 import java.util.Map;
\r
15 * Concrete class for ComparisonResultSet. This instance compare class
\r
16 * files by certain pair. The pair is guessed by system with class
\r
17 * name, or specified by user.
\r
19 * @author Haruaki TAMADA
\r
20 * @version $Revision$ $Date$
\r
22 public class CertainPairComparisonResultSet implements ComparisonResultSet{
\r
23 private BirthmarkEnvironment environment;
\r
24 private List<ComparisonPair> pairList = new ArrayList<ComparisonPair>();
\r
25 private Map<URL, BirthmarkSet> sources = new HashMap<URL, BirthmarkSet>();
\r
28 * This constructor is the comparison pair list is specified.
\r
30 public CertainPairComparisonResultSet(ComparisonPair[] pairs, BirthmarkEnvironment environment){
\r
31 this.environment = environment;
\r
32 for(int i = 0; i < pairs.length; i++){
\r
33 pairList.add(pairs[i]);
\r
34 sources.put(pairs[i].getTarget1().getLocation(), pairs[i].getTarget1());
\r
35 sources.put(pairs[i].getTarget2().getLocation(), pairs[i].getTarget2());
\r
40 * This constructor is the comparison pair was guessed with class name.
\r
42 public CertainPairComparisonResultSet(BirthmarkSet[] targetX, BirthmarkSet[] targetY, BirthmarkEnvironment environment){
\r
43 this.environment = environment;
\r
44 for(int i = 0; i < targetX.length; i++){
\r
45 BirthmarkSet target2 = findTarget(targetX[i].getName(), targetY);
\r
47 if(target2 != null){
\r
48 pairList.add(new ComparisonPair(targetX[i], target2, environment));
\r
51 addSources(targetX);
\r
52 addSources(targetY);
\r
56 * This constructor is the comparison pair was specified as mapping.
\r
58 public CertainPairComparisonResultSet(BirthmarkSet[] targetX, BirthmarkSet[] targetY, Map<String, String> mapping, BirthmarkEnvironment environment){
\r
59 this.environment = environment;
\r
60 for(Map.Entry<String, String> entry: mapping.entrySet()){
\r
61 BirthmarkSet target1 = findTarget(entry.getKey(), targetX);
\r
62 BirthmarkSet target2 = findTarget(entry.getValue(), targetY);
\r
63 if(target1 == null && target2 == null){
\r
64 target1 = findTarget(entry.getKey(), targetY);
\r
65 target2 = findTarget(entry.getValue(), targetX);
\r
66 if(target1 != null && target2 != null){
\r
67 // mapping table is swapped.
\r
68 BirthmarkSet[] tmp = targetX;
\r
73 if(target1 != null && target2 != null){
\r
74 pairList.add(new ComparisonPair(target1, target2, environment));
\r
77 addSources(targetX);
\r
78 addSources(targetY);
\r
82 * return the environment.
\r
84 public BirthmarkEnvironment getEnvironment(){
\r
89 * return comparison count.
\r
91 public int getComparisonCount(){
\r
92 return pairList.size();
\r
96 * return the iterator of each pair.
\r
98 public Iterator<ComparisonPair> iterator(){
\r
99 return pairList.iterator();
\r
102 public BirthmarkSet[] getComparisonSources(){
\r
103 BirthmarkSet[] entries = new BirthmarkSet[sources.size()];
\r
105 for(Map.Entry<URL, BirthmarkSet> entry: sources.entrySet()){
\r
106 entries[index] = entry.getValue();
\r
113 * find BirthmarkSet from given array by given class name.
\r
115 private BirthmarkSet findTarget(String className, BirthmarkSet[] target){
\r
116 for(int i = 0; i < target.length; i++){
\r
117 if(className.equals(target[i].getName())){
\r
124 private void addSources(BirthmarkSet[] bs){
\r
125 for(BirthmarkSet s: bs){
\r
126 sources.put(s.getLocation(), s);
\r