Clover coverage report - PMD - 3.7 Coverage timestamp: Wed May 31 2006 09:25:59 EDT FRAMES NO FRAMES |

file stats: | LOC: | 129 |  | Methods: | 22
| NCLOC: | 95 |  | Classes: | 2

Source file | Conditionals | Statements | Methods | TOTAL
Match.java | 100% | 90.9% | 86.4% | 89.8% |

1 |  | /**
2 |  | * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 |  | */
4 |  | package net.sourceforge.pmd.cpd;
5 |  |
6 |  | import net.sourceforge.pmd.PMD;
7 |  |
8 |  | import java.util.Iterator;
9 |  | import java.util.Set;
10 |  | import java.util.TreeSet;
11 |  |
12 |  | public class Match implements Comparable {
13 |  |
14 |  | private int tokenCount;
15 |  | private int lineCount;
16 |  | private Set markSet = new TreeSet();
17 |  | private TokenEntry[] marks = new TokenEntry[2];
18 |  | private String code;
19 |  | private MatchCode mc;
20 |  |
21 |  | public static class MatchCode {
22 |  |
23 |  | private int first;
24 |  | private int second;
25 |  |
26 | 2 | public MatchCode() {
27 |  | }
28 |  |
29 | 4 | public MatchCode(TokenEntry m1, TokenEntry m2) {
30 | 4 | first = m1.getIndex();
31 | 4 | second = m2.getIndex();
32 |  | }
33 |  |
34 | 10 | public int hashCode() {
35 | 10 | return first + 37 * second;
36 |  | }
37 |  |
38 | 3 | public boolean equals(Object other) {
39 | 3 | MatchCode mc = (MatchCode) other;
40 | 3 | return mc.first == first && mc.second == second;
41 |  | }
42 |  |
43 | 3 | public void setFirst(int first) {
44 | 3 | this.first = first;
45 |  | }
46 |  |
47 | 3 | public void setSecond(int second) {
48 | 3 | this.second = second;
49 |  | }
50 |  |
51 |  | }
52 |  |
53 | 10 | public Match(int tokenCount, TokenEntry first, TokenEntry second) {
54 | 10 | markSet.add(first);
55 | 10 | markSet.add(second);
56 | 10 | marks[0] = first;
57 | 10 | marks[1] = second;
58 | 10 | this.tokenCount = tokenCount;
59 |  | }
60 |  |
61 | 0 | public int getMarkCount() {
62 | 0 | return markSet.size();
63 |  | }
64 |  |
65 | 9 | public void setLineCount(int lineCount) {
66 | 9 | this.lineCount = lineCount;
67 |  | }
68 |  |
69 | 6 | public int getLineCount() {
70 | 6 | return this.lineCount;
71 |  | }
72 |  |
73 | 27 | public int getTokenCount() {
74 | 27 | return this.tokenCount;
75 |  | }
76 |  |
77 | 5 | public String getSourceCodeSlice() {
78 | 5 | return this.code;
79 |  | }
80 |  |
81 | 6 | public void setSourceCodeSlice(String code) {
82 | 6 | this.code = code;
83 |  | }
84 |  |
85 | 8 | public Iterator iterator() {
86 | 8 | return markSet.iterator();
87 |  | }
88 |  |
89 | 4 | public int compareTo(Object o) {
90 | 4 | Match other = (Match) o;
91 | 4 | int diff = other.getTokenCount() - getTokenCount();
92 | 4 | if (diff != 0) {
93 | 1 | return diff;
94 |  | }
95 | 3 | return other.getFirstMark().getIndex() - getFirstMark().getIndex();
96 |  | }
97 |  |
98 | 9 | public TokenEntry getFirstMark() {
99 | 9 | return marks[0];
100 |  | }
101 |  |
102 | 1 | public TokenEntry getSecondMark() {
103 | 1 | return marks[1];
104 |  | }
105 |  |
106 | 0 | public String toString() {
107 | 0 | return "Match: " + PMD.EOL + "tokenCount = " + tokenCount + PMD.EOL + "marks = " + markSet.size();
108 |  | }
109 |  |
110 | 9 | public Set getMarkSet() {
111 | 9 | return markSet;
112 |  | }
113 |  |
114 | 7 | public MatchCode getMatchCode() {
115 | 7 | if (mc == null) {
116 | 4 | mc = new MatchCode(marks[0], marks[1]);
117 |  | }
118 | 7 | return mc;
119 |  | }
120 |  |
121 | 1 | public int getEndIndex() {
122 | 1 | return marks[1].getIndex() + getTokenCount() - 1;
123 |  | }
124 |  |
125 | 0 | public void setMarkSet(Set markSet) {
126 | 0 | this.markSet = markSet;
127 |  | }
128 |  |
129 |  | }