1 | /* |
---|
2 | * |
---|
3 | */ |
---|
4 | package de.ugoe.cs.autoquest.tasktrees.alignment.algorithms; |
---|
5 | |
---|
6 | import java.io.Serializable; |
---|
7 | import java.util.ArrayList; |
---|
8 | import java.util.Iterator; |
---|
9 | import java.util.LinkedList; |
---|
10 | |
---|
11 | // TODO: Auto-generated Javadoc |
---|
12 | /** |
---|
13 | * The Class Match. |
---|
14 | */ |
---|
15 | public class Match implements Cloneable,Comparable<Match>,Serializable { |
---|
16 | |
---|
17 | /** The Constant serialVersionUID. */ |
---|
18 | private static final long serialVersionUID = -3206992723755714741L; |
---|
19 | |
---|
20 | /** The matchseqs. */ |
---|
21 | private final ArrayList<NumberSequence> matchseqs; |
---|
22 | |
---|
23 | /** The occurences. */ |
---|
24 | private LinkedList<MatchOccurrence> occurrences; |
---|
25 | |
---|
26 | /** |
---|
27 | * Instantiates a new match. |
---|
28 | */ |
---|
29 | public Match() { |
---|
30 | matchseqs = new ArrayList<NumberSequence>(2); |
---|
31 | occurrences = new LinkedList<MatchOccurrence>(); |
---|
32 | matchseqs.add(null); |
---|
33 | matchseqs.add(null); |
---|
34 | } // TODO Auto-generated method stub |
---|
35 | |
---|
36 | /** |
---|
37 | * Adds the occurence. |
---|
38 | * |
---|
39 | * @param occurence the occurence |
---|
40 | */ |
---|
41 | public void addOccurence(MatchOccurrence occurence) { |
---|
42 | occurrences.add(occurence); |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | * Adds the occurrences of given match to this match . |
---|
47 | * |
---|
48 | * @param m the match the occurrences should be merged with this one |
---|
49 | */ |
---|
50 | public void addOccurencesOf(Match m) { |
---|
51 | occurrences.addAll(m.getOccurences()); |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * Equals. |
---|
56 | * |
---|
57 | * @param m the Match the equality should be checked against |
---|
58 | * @return true, if both Matches are equal |
---|
59 | */ |
---|
60 | public boolean equals(Match m) { |
---|
61 | if ((m.getFirstSequence().equals(this.getFirstSequence()) || m |
---|
62 | .getFirstSequence().equals(this.getSecondSequence())) |
---|
63 | && (m.getSecondSequence().equals(this.getFirstSequence()) || m |
---|
64 | .getSecondSequence().equals(this.getSecondSequence()))) { |
---|
65 | return true; |
---|
66 | } |
---|
67 | return false; |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * Gets the first sequence. |
---|
72 | * |
---|
73 | * @return the first sequence |
---|
74 | */ |
---|
75 | public NumberSequence getFirstSequence() { |
---|
76 | return matchseqs.get(0); |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | * Gets the occurrences. |
---|
81 | * |
---|
82 | * @return the occurrences |
---|
83 | */ |
---|
84 | public LinkedList<MatchOccurrence> getOccurences() { |
---|
85 | return occurrences; |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * Gets the second sequence. |
---|
90 | * |
---|
91 | * @return the second sequence |
---|
92 | */ |
---|
93 | public NumberSequence getSecondSequence() { |
---|
94 | return matchseqs.get(1); |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * Occurrence count. |
---|
99 | * |
---|
100 | * @return the number of occurrences of this match |
---|
101 | */ |
---|
102 | public int occurenceCount() { |
---|
103 | return occurrences.size(); |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * Sets the first sequence. |
---|
108 | * |
---|
109 | * @param seq the new first sequence |
---|
110 | */ |
---|
111 | public void setFirstSequence(NumberSequence seq) { |
---|
112 | matchseqs.set(0, seq); |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * Sets the occurrences. |
---|
117 | * |
---|
118 | * @param occurences the new occurrences |
---|
119 | */ |
---|
120 | public void setOccurences(LinkedList<MatchOccurrence> occurences) { |
---|
121 | this.occurrences = occurences; |
---|
122 | } |
---|
123 | |
---|
124 | /** |
---|
125 | * Sets the second sequence. |
---|
126 | * |
---|
127 | * @param seq the new second sequence |
---|
128 | */ |
---|
129 | public void setSecondSequence(NumberSequence seq) { |
---|
130 | matchseqs.set(1, seq); |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | /** |
---|
135 | * Occurrence id sum. Used for comparing and sorting matches |
---|
136 | * |
---|
137 | * @return the sum of all occurrence ids. |
---|
138 | */ |
---|
139 | public int ocurrenceIDSum() { |
---|
140 | int sum = 0; |
---|
141 | for(Iterator<MatchOccurrence> it = occurrences.iterator();it.hasNext();) { |
---|
142 | MatchOccurrence mo = it.next(); |
---|
143 | sum+=mo.getSequenceId(); |
---|
144 | } |
---|
145 | return sum; |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | * Task id sum. Used for comparing and sorting matches |
---|
150 | * |
---|
151 | * @return the int |
---|
152 | */ |
---|
153 | public int taskIdSum() { |
---|
154 | int sum = 0; |
---|
155 | int[] first = this.getFirstSequence().getSequence(); |
---|
156 | int[] second = this.getSecondSequence().getSequence(); |
---|
157 | for(int i = 0;i < this.getFirstSequence().size();i++) { |
---|
158 | sum= first[i]+second[i]; |
---|
159 | } |
---|
160 | return sum; |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | /** |
---|
166 | * Clone without occurrences. |
---|
167 | * |
---|
168 | * @return the match |
---|
169 | * @throws CloneNotSupportedException the clone not supported exception |
---|
170 | */ |
---|
171 | public Match cloneWithoutOccurrences() { |
---|
172 | Match result = new Match(); |
---|
173 | result.setFirstSequence(this.getFirstSequence()); |
---|
174 | result.setSecondSequence(this.getSecondSequence()); |
---|
175 | return result; |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | |
---|
180 | /** |
---|
181 | * Size. |
---|
182 | * |
---|
183 | * @return the size (number of aligned tasks) |
---|
184 | */ |
---|
185 | public int size() { |
---|
186 | // Both sequences should be equally long |
---|
187 | return matchseqs.get(0).size(); |
---|
188 | } |
---|
189 | |
---|
190 | /* (non-Javadoc) |
---|
191 | * @see java.lang.Comparable#compareTo(java.lang.Object) |
---|
192 | */ |
---|
193 | @Override |
---|
194 | public int compareTo(Match arg0) { |
---|
195 | |
---|
196 | return 0; |
---|
197 | } |
---|
198 | |
---|
199 | } |
---|