summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/convert/Matches.java
diff options
context:
space:
mode:
authorGravatar jeff2015-02-28 23:36:47 -0500
committerGravatar jeff2015-02-28 23:36:47 -0500
commit88671184e20b3ad3791125cf96c83ca048cb2861 (patch)
tree6c86f1ea61666ff2584b434d5f8df4d3fd83263c /src/cuchaz/enigma/convert/Matches.java
parentswitch to better-maintained version of JSyntaxPane (diff)
downloadenigma-fork-88671184e20b3ad3791125cf96c83ca048cb2861.tar.gz
enigma-fork-88671184e20b3ad3791125cf96c83ca048cb2861.tar.xz
enigma-fork-88671184e20b3ad3791125cf96c83ca048cb2861.zip
refactor converter a bit for upcoming convert gui
Diffstat (limited to 'src/cuchaz/enigma/convert/Matches.java')
-rw-r--r--src/cuchaz/enigma/convert/Matches.java89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/convert/Matches.java b/src/cuchaz/enigma/convert/Matches.java
new file mode 100644
index 0000000..75ecc2a
--- /dev/null
+++ b/src/cuchaz/enigma/convert/Matches.java
@@ -0,0 +1,89 @@
1package cuchaz.enigma.convert;
2
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.Iterator;
6import java.util.Map;
7import java.util.Set;
8
9import com.google.common.collect.BiMap;
10import com.google.common.collect.HashBiMap;
11import com.google.common.collect.Maps;
12import com.google.common.collect.Sets;
13
14import cuchaz.enigma.mapping.ClassEntry;
15
16
17public class Matches implements Iterable<ClassMatch> {
18
19 Collection<ClassMatch> m_matches;
20 BiMap<ClassEntry,ClassEntry> m_uniqueMatches;
21 Map<ClassEntry,ClassMatch> m_ambiguousMatchesBySource;
22 Map<ClassEntry,ClassMatch> m_ambiguousMatchesByDest;
23 Set<ClassEntry> m_unmatchedSourceClasses;
24 Set<ClassEntry> m_unmatchedDestClasses;
25
26 public Matches() {
27 this(new ArrayList<ClassMatch>());
28 }
29
30 public Matches(Collection<ClassMatch> matches) {
31 m_matches = matches;
32 m_uniqueMatches = HashBiMap.create();
33 m_ambiguousMatchesBySource = Maps.newHashMap();
34 m_ambiguousMatchesByDest = Maps.newHashMap();
35 m_unmatchedSourceClasses = Sets.newHashSet();
36 m_unmatchedDestClasses = Sets.newHashSet();
37
38 for (ClassMatch match : matches) {
39 indexMatch(match);
40 }
41 }
42
43 public void add(ClassMatch match) {
44 m_matches.add(match);
45 indexMatch(match);
46 }
47
48 public int size() {
49 return m_matches.size();
50 }
51
52 @Override
53 public Iterator<ClassMatch> iterator() {
54 return m_matches.iterator();
55 }
56
57 private void indexMatch(ClassMatch match) {
58 if (!match.isMatched()) {
59 // unmatched
60 m_unmatchedSourceClasses.addAll(match.sourceClasses);
61 m_unmatchedDestClasses.addAll(match.destClasses);
62 } else {
63 if (match.isAmbiguous()) {
64 // ambiguously matched
65 for (ClassEntry entry : match.sourceClasses) {
66 m_ambiguousMatchesBySource.put(entry, match);
67 }
68 for (ClassEntry entry : match.destClasses) {
69 m_ambiguousMatchesByDest.put(entry, match);
70 }
71 } else {
72 // uniquely matched
73 m_uniqueMatches.put(match.getUniqueSource(), match.getUniqueDest());
74 }
75 }
76 }
77
78 public BiMap<ClassEntry,ClassEntry> getUniqueMatches() {
79 return m_uniqueMatches;
80 }
81
82 public Set<ClassEntry> getUnmatchedSourceClasses() {
83 return m_unmatchedSourceClasses;
84 }
85
86 public Set<ClassEntry> getUnmatchedDestClasses() {
87 return m_unmatchedDestClasses;
88 }
89}