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