summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/convert/Matches.java
diff options
context:
space:
mode:
authorGravatar jeff2015-03-09 12:53:11 -0400
committerGravatar jeff2015-03-09 12:53:11 -0400
commitd6b2a223a7973941e5e4fb45c8ceec4885891496 (patch)
tree5728ab513d0b4ed85a720da7eb48c6591dd3f8b0 /src/cuchaz/enigma/convert/Matches.java
parentadd tracking for mismatched fields/methods (diff)
downloadenigma-fork-d6b2a223a7973941e5e4fb45c8ceec4885891496.tar.gz
enigma-fork-d6b2a223a7973941e5e4fb45c8ceec4885891496.tar.xz
enigma-fork-d6b2a223a7973941e5e4fb45c8ceec4885891496.zip
starting on field matching gui
Diffstat (limited to 'src/cuchaz/enigma/convert/Matches.java')
-rw-r--r--src/cuchaz/enigma/convert/Matches.java153
1 files changed, 0 insertions, 153 deletions
diff --git a/src/cuchaz/enigma/convert/Matches.java b/src/cuchaz/enigma/convert/Matches.java
deleted file mode 100644
index 19bb155..0000000
--- a/src/cuchaz/enigma/convert/Matches.java
+++ /dev/null
@@ -1,153 +0,0 @@
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 Map<ClassEntry,ClassMatch> m_matchesBySource;
21 Map<ClassEntry,ClassMatch> m_matchesByDest;
22 BiMap<ClassEntry,ClassEntry> m_uniqueMatches;
23 Map<ClassEntry,ClassMatch> m_ambiguousMatchesBySource;
24 Map<ClassEntry,ClassMatch> m_ambiguousMatchesByDest;
25 Set<ClassEntry> m_unmatchedSourceClasses;
26 Set<ClassEntry> m_unmatchedDestClasses;
27
28 public Matches() {
29 this(new ArrayList<ClassMatch>());
30 }
31
32 public Matches(Collection<ClassMatch> matches) {
33 m_matches = matches;
34 m_matchesBySource = Maps.newHashMap();
35 m_matchesByDest = Maps.newHashMap();
36 m_uniqueMatches = HashBiMap.create();
37 m_ambiguousMatchesBySource = Maps.newHashMap();
38 m_ambiguousMatchesByDest = Maps.newHashMap();
39 m_unmatchedSourceClasses = Sets.newHashSet();
40 m_unmatchedDestClasses = Sets.newHashSet();
41
42 for (ClassMatch match : matches) {
43 indexMatch(match);
44 }
45 }
46
47 public void add(ClassMatch match) {
48 m_matches.add(match);
49 indexMatch(match);
50 }
51
52 public void remove(ClassMatch match) {
53 for (ClassEntry sourceClass : match.sourceClasses) {
54 m_matchesBySource.remove(sourceClass);
55 m_uniqueMatches.remove(sourceClass);
56 m_ambiguousMatchesBySource.remove(sourceClass);
57 m_unmatchedSourceClasses.remove(sourceClass);
58 }
59 for (ClassEntry destClass : match.destClasses) {
60 m_matchesByDest.remove(destClass);
61 m_uniqueMatches.inverse().remove(destClass);
62 m_ambiguousMatchesByDest.remove(destClass);
63 m_unmatchedDestClasses.remove(destClass);
64 }
65 m_matches.remove(match);
66 }
67
68 public int size() {
69 return m_matches.size();
70 }
71
72 @Override
73 public Iterator<ClassMatch> iterator() {
74 return m_matches.iterator();
75 }
76
77 private void indexMatch(ClassMatch match) {
78 if (!match.isMatched()) {
79 // unmatched
80 m_unmatchedSourceClasses.addAll(match.sourceClasses);
81 m_unmatchedDestClasses.addAll(match.destClasses);
82 } else {
83 if (match.isAmbiguous()) {
84 // ambiguously matched
85 for (ClassEntry entry : match.sourceClasses) {
86 m_ambiguousMatchesBySource.put(entry, match);
87 }
88 for (ClassEntry entry : match.destClasses) {
89 m_ambiguousMatchesByDest.put(entry, match);
90 }
91 } else {
92 // uniquely matched
93 m_uniqueMatches.put(match.getUniqueSource(), match.getUniqueDest());
94 }
95 }
96 for (ClassEntry entry : match.sourceClasses) {
97 m_matchesBySource.put(entry, match);
98 }
99 for (ClassEntry entry : match.destClasses) {
100 m_matchesByDest.put(entry, match);
101 }
102 }
103
104 public BiMap<ClassEntry,ClassEntry> getUniqueMatches() {
105 return m_uniqueMatches;
106 }
107
108 public Set<ClassEntry> getUnmatchedSourceClasses() {
109 return m_unmatchedSourceClasses;
110 }
111
112 public Set<ClassEntry> getUnmatchedDestClasses() {
113 return m_unmatchedDestClasses;
114 }
115
116 public Set<ClassEntry> getAmbiguouslyMatchedSourceClasses() {
117 return m_ambiguousMatchesBySource.keySet();
118 }
119
120 public ClassMatch getAmbiguousMatchBySource(ClassEntry sourceClass) {
121 return m_ambiguousMatchesBySource.get(sourceClass);
122 }
123
124 public ClassMatch getMatchBySource(ClassEntry sourceClass) {
125 return m_matchesBySource.get(sourceClass);
126 }
127
128 public ClassMatch getMatchByDest(ClassEntry destClass) {
129 return m_matchesByDest.get(destClass);
130 }
131
132 public void removeSource(ClassEntry sourceClass) {
133 ClassMatch match = m_matchesBySource.get(sourceClass);
134 if (match != null) {
135 remove(match);
136 match.sourceClasses.remove(sourceClass);
137 if (!match.sourceClasses.isEmpty() || !match.destClasses.isEmpty()) {
138 add(match);
139 }
140 }
141 }
142
143 public void removeDest(ClassEntry destClass) {
144 ClassMatch match = m_matchesByDest.get(destClass);
145 if (match != null) {
146 remove(match);
147 match.destClasses.remove(destClass);
148 if (!match.sourceClasses.isEmpty() || !match.destClasses.isEmpty()) {
149 add(match);
150 }
151 }
152 }
153}