|
1 |
| -package nnwl.jduplicatefinder.engine; |
2 |
| - |
3 |
| -import nnwl.jduplicatefinder.engine.comparators.AbstractDuplicateComparator; |
4 |
| -import org.apache.log4j.Logger; |
5 |
| - |
6 |
| -import java.nio.file.Path; |
7 |
| -import java.util.ArrayList; |
8 |
| -import java.util.List; |
9 |
| -import java.util.Map; |
10 |
| -import java.util.TreeMap; |
11 |
| - |
12 |
| -/** |
13 |
| - * JDuplicateFinder |
14 |
| - * |
15 |
| - * @author Anael Ollier <nanawel NOSPAM [at] gmail [dot] com> |
16 |
| - * @license GPLv3 - See LICENSE |
17 |
| - */ |
18 |
| -public class FileResult { |
19 |
| - |
20 |
| - private static final Logger logger = Logger.getLogger(FileResult.class); |
21 |
| - |
22 |
| - public static final int UNIQUE = 0; |
23 |
| - public static final int NOT_UNIQUE = 1; |
24 |
| - |
25 |
| - protected Path referenceFile; |
26 |
| - |
27 |
| - protected List<SimilarityResult> similarityResults = new ArrayList<SimilarityResult>(); |
28 |
| - |
29 |
| - protected int status; |
30 |
| - |
31 |
| - protected List<AbstractDuplicateComparator> currentRunComparators; |
32 |
| - |
33 |
| - protected Map<String, ? extends SimilarityResult> combinedSimilarityResults; |
34 |
| - |
35 |
| - public FileResult(Path file) { |
36 |
| - this.referenceFile = file; |
37 |
| - } |
38 |
| - |
39 |
| - public FileResult(Path file, List<SimilarityResult> similarityResults) { |
40 |
| - this(file); |
41 |
| - this.appendSimilarityResults(similarityResults); |
42 |
| - } |
43 |
| - |
44 |
| - public Path getReferenceFile() { |
45 |
| - return referenceFile; |
46 |
| - } |
47 |
| - |
48 |
| - public List<SimilarityResult> getSimilarityResults() { |
49 |
| - return similarityResults; |
50 |
| - } |
51 |
| - |
52 |
| - public int getStatus() { |
53 |
| - return status; |
54 |
| - } |
55 |
| - |
56 |
| - public void appendSimilarityResult(SimilarityResult similarResult) { |
57 |
| - this.similarityResults.add(similarResult); |
58 |
| - this.updateStatus(); |
59 |
| - this.combinedSimilarityResults = null; |
60 |
| - } |
61 |
| - |
62 |
| - public void appendSimilarityResults(List<SimilarityResult> similarityResults) { |
63 |
| - this.similarityResults.addAll(similarityResults); |
64 |
| - this.updateStatus(); |
65 |
| - this.combinedSimilarityResults = null; |
66 |
| - } |
67 |
| - |
68 |
| - protected void updateStatus() { |
69 |
| - if (this.similarityResults.isEmpty()) { |
70 |
| - this.status = UNIQUE; |
71 |
| - } else { |
72 |
| - this.status = NOT_UNIQUE; |
73 |
| - } |
74 |
| - } |
75 |
| - |
76 |
| - public void setCurrentRunComparators(List<AbstractDuplicateComparator> comparators) { |
77 |
| - this.currentRunComparators = comparators; |
78 |
| - } |
79 |
| - |
80 |
| - public Map<String, ? extends SimilarityResult> getCombinedSimilarityResults() { |
81 |
| - if (this.combinedSimilarityResults == null) { |
82 |
| - Map<String, CombinedSimilarityResult> combinedSimilarityResults = new TreeMap<>(); |
83 |
| - for (SimilarityResult sr : this.similarityResults) { |
84 |
| - CombinedSimilarityResult csr; |
85 |
| - if (combinedSimilarityResults.containsKey(sr.getSimilarFile().toString())) { |
86 |
| - csr = combinedSimilarityResults.get(sr.getSimilarFile().toString()); |
87 |
| - csr.addSimilarityResult(sr); |
88 |
| - } else { |
89 |
| - csr = new CombinedSimilarityResult(sr); |
90 |
| - csr.setComparators(this.currentRunComparators); |
91 |
| - combinedSimilarityResults.put(csr.getSimilarFile().toString(), csr); |
92 |
| - } |
93 |
| - } |
94 |
| - this.combinedSimilarityResults = combinedSimilarityResults; |
95 |
| - } |
96 |
| - return this.combinedSimilarityResults; |
97 |
| - } |
98 |
| -} |
| 1 | +package nnwl.jduplicatefinder.engine; |
| 2 | + |
| 3 | +import nnwl.jduplicatefinder.engine.comparators.AbstractDuplicateComparator; |
| 4 | +import org.apache.log4j.Logger; |
| 5 | + |
| 6 | +import java.nio.file.Path; |
| 7 | +import java.util.ArrayList; |
| 8 | +import java.util.List; |
| 9 | +import java.util.Map; |
| 10 | +import java.util.TreeMap; |
| 11 | + |
| 12 | +/** |
| 13 | + * JDuplicateFinder |
| 14 | + * |
| 15 | + * @author Anael Ollier <nanawel NOSPAM [at] gmail [dot] com> |
| 16 | + * @license GPLv3 - See LICENSE |
| 17 | + */ |
| 18 | +public class FileResult { |
| 19 | + |
| 20 | + private static final Logger logger = Logger.getLogger(FileResult.class); |
| 21 | + |
| 22 | + public static final int UNIQUE = 0; |
| 23 | + public static final int NOT_UNIQUE = 1; |
| 24 | + |
| 25 | + protected Path referenceFile; |
| 26 | + |
| 27 | + protected List<SimilarityResult> similarityResults = new ArrayList<SimilarityResult>(); |
| 28 | + |
| 29 | + protected int status; |
| 30 | + |
| 31 | + protected List<AbstractDuplicateComparator> currentRunComparators; |
| 32 | + |
| 33 | + protected Map<String, ? extends SimilarityResult> combinedSimilarityResults; |
| 34 | + |
| 35 | + public FileResult(Path file) { |
| 36 | + this.referenceFile = file; |
| 37 | + } |
| 38 | + |
| 39 | + public FileResult(Path file, List<SimilarityResult> similarityResults) { |
| 40 | + this(file); |
| 41 | + this.appendSimilarityResults(similarityResults); |
| 42 | + } |
| 43 | + |
| 44 | + public Path getReferenceFile() { |
| 45 | + return referenceFile; |
| 46 | + } |
| 47 | + |
| 48 | + public List<SimilarityResult> getSimilarityResults() { |
| 49 | + return similarityResults; |
| 50 | + } |
| 51 | + |
| 52 | + public int getStatus() { |
| 53 | + return status; |
| 54 | + } |
| 55 | + |
| 56 | + public void appendSimilarityResult(SimilarityResult similarResult) { |
| 57 | + this.similarityResults.add(similarResult); |
| 58 | + this.updateStatus(); |
| 59 | + this.combinedSimilarityResults = null; |
| 60 | + } |
| 61 | + |
| 62 | + public void appendSimilarityResults(List<SimilarityResult> similarityResults) { |
| 63 | + this.similarityResults.addAll(similarityResults); |
| 64 | + this.updateStatus(); |
| 65 | + this.combinedSimilarityResults = null; |
| 66 | + } |
| 67 | + |
| 68 | + protected void updateStatus() { |
| 69 | + if (this.similarityResults.isEmpty()) { |
| 70 | + this.status = UNIQUE; |
| 71 | + } else { |
| 72 | + this.status = NOT_UNIQUE; |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + public void setCurrentRunComparators(List<AbstractDuplicateComparator> comparators) { |
| 77 | + this.currentRunComparators = comparators; |
| 78 | + } |
| 79 | + |
| 80 | + public Map<String, ? extends SimilarityResult> getCombinedSimilarityResults() { |
| 81 | + if (this.combinedSimilarityResults == null) { |
| 82 | + Map<String, CombinedSimilarityResult> combinedSimilarityResults = new TreeMap<>(); |
| 83 | + for (SimilarityResult sr : this.similarityResults) { |
| 84 | + CombinedSimilarityResult csr; |
| 85 | + if (combinedSimilarityResults.containsKey(sr.getSimilarFile().toString())) { |
| 86 | + csr = combinedSimilarityResults.get(sr.getSimilarFile().toString()); |
| 87 | + csr.addSimilarityResult(sr); |
| 88 | + } else { |
| 89 | + csr = new CombinedSimilarityResult(sr); |
| 90 | + csr.setComparators(this.currentRunComparators); |
| 91 | + combinedSimilarityResults.put(csr.getSimilarFile().toString(), csr); |
| 92 | + } |
| 93 | + } |
| 94 | + this.combinedSimilarityResults = combinedSimilarityResults; |
| 95 | + } |
| 96 | + return this.combinedSimilarityResults; |
| 97 | + } |
| 98 | + |
| 99 | + public String toString() { |
| 100 | + StringBuilder sb = new StringBuilder(); |
| 101 | + |
| 102 | + sb.append(this.getClass()) |
| 103 | + .append(": ") |
| 104 | + .append(this.referenceFile.toString()) |
| 105 | + .append(" {\n"); |
| 106 | + for (Map.Entry<String, ? extends SimilarityResult> csr : this.getCombinedSimilarityResults().entrySet()) { |
| 107 | + sb.append(String.format(" [%3d] ", csr.getValue().getSimilarity())) |
| 108 | + .append(csr.getValue().getSimilarFile().toString()) |
| 109 | + .append("\n"); |
| 110 | + } |
| 111 | + sb.append("}"); |
| 112 | + |
| 113 | + return sb.toString(); |
| 114 | + } |
| 115 | +} |
0 commit comments