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