summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/convert/ClassMatches.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/ClassMatches.java')
-rw-r--r--src/main/java/cuchaz/enigma/convert/ClassMatches.java273
1 files changed, 136 insertions, 137 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatches.java b/src/main/java/cuchaz/enigma/convert/ClassMatches.java
index 431c4f2..db2c550 100644
--- a/src/main/java/cuchaz/enigma/convert/ClassMatches.java
+++ b/src/main/java/cuchaz/enigma/convert/ClassMatches.java
@@ -8,152 +8,151 @@
8 * Contributors: 8 * Contributors:
9 * Jeff Martin - initial API and implementation 9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11
11package cuchaz.enigma.convert; 12package cuchaz.enigma.convert;
12 13
13import com.google.common.collect.BiMap; 14import com.google.common.collect.BiMap;
14import com.google.common.collect.HashBiMap; 15import com.google.common.collect.HashBiMap;
15import com.google.common.collect.Maps; 16import com.google.common.collect.Maps;
16import com.google.common.collect.Sets; 17import com.google.common.collect.Sets;
17
18import java.util.*;
19
20import cuchaz.enigma.mapping.ClassEntry; 18import cuchaz.enigma.mapping.ClassEntry;
21 19
20import java.util.*;
22 21
23public class ClassMatches implements Iterable<ClassMatch> { 22public class ClassMatches implements Iterable<ClassMatch> {
24 23
25 private Collection<ClassMatch> matches; 24 private Collection<ClassMatch> matches;
26 private Map<ClassEntry, ClassMatch> matchesBySource; 25 private Map<ClassEntry, ClassMatch> matchesBySource;
27 private Map<ClassEntry, ClassMatch> matchesByDest; 26 private Map<ClassEntry, ClassMatch> matchesByDest;
28 private BiMap<ClassEntry, ClassEntry> uniqueMatches; 27 private BiMap<ClassEntry, ClassEntry> uniqueMatches;
29 private Map<ClassEntry, ClassMatch> ambiguousMatchesBySource; 28 private Map<ClassEntry, ClassMatch> ambiguousMatchesBySource;
30 private Map<ClassEntry, ClassMatch> ambiguousMatchesByDest; 29 private Map<ClassEntry, ClassMatch> ambiguousMatchesByDest;
31 private Set<ClassEntry> unmatchedSourceClasses; 30 private Set<ClassEntry> unmatchedSourceClasses;
32 private Set<ClassEntry> unmatchedDestClasses; 31 private Set<ClassEntry> unmatchedDestClasses;
33 32
34 public ClassMatches() { 33 public ClassMatches() {
35 this(new ArrayList<>()); 34 this(new ArrayList<>());
36 } 35 }
37 36
38 public ClassMatches(Collection<ClassMatch> matches) { 37 public ClassMatches(Collection<ClassMatch> matches) {
39 this.matches = matches; 38 this.matches = matches;
40 matchesBySource = Maps.newHashMap(); 39 matchesBySource = Maps.newHashMap();
41 matchesByDest = Maps.newHashMap(); 40 matchesByDest = Maps.newHashMap();
42 uniqueMatches = HashBiMap.create(); 41 uniqueMatches = HashBiMap.create();
43 ambiguousMatchesBySource = Maps.newHashMap(); 42 ambiguousMatchesBySource = Maps.newHashMap();
44 ambiguousMatchesByDest = Maps.newHashMap(); 43 ambiguousMatchesByDest = Maps.newHashMap();
45 unmatchedSourceClasses = Sets.newHashSet(); 44 unmatchedSourceClasses = Sets.newHashSet();
46 unmatchedDestClasses = Sets.newHashSet(); 45 unmatchedDestClasses = Sets.newHashSet();
47 46
48 for (ClassMatch match : matches) { 47 for (ClassMatch match : matches) {
49 indexMatch(match); 48 indexMatch(match);
50 } 49 }
51 } 50 }
52 51
53 public void add(ClassMatch match) { 52 public void add(ClassMatch match) {
54 matches.add(match); 53 matches.add(match);
55 indexMatch(match); 54 indexMatch(match);
56 } 55 }
57 56
58 public void remove(ClassMatch match) { 57 public void remove(ClassMatch match) {
59 for (ClassEntry sourceClass : match.sourceClasses) { 58 for (ClassEntry sourceClass : match.sourceClasses) {
60 matchesBySource.remove(sourceClass); 59 matchesBySource.remove(sourceClass);
61 uniqueMatches.remove(sourceClass); 60 uniqueMatches.remove(sourceClass);
62 ambiguousMatchesBySource.remove(sourceClass); 61 ambiguousMatchesBySource.remove(sourceClass);
63 unmatchedSourceClasses.remove(sourceClass); 62 unmatchedSourceClasses.remove(sourceClass);
64 } 63 }
65 for (ClassEntry destClass : match.destClasses) { 64 for (ClassEntry destClass : match.destClasses) {
66 matchesByDest.remove(destClass); 65 matchesByDest.remove(destClass);
67 uniqueMatches.inverse().remove(destClass); 66 uniqueMatches.inverse().remove(destClass);
68 ambiguousMatchesByDest.remove(destClass); 67 ambiguousMatchesByDest.remove(destClass);
69 unmatchedDestClasses.remove(destClass); 68 unmatchedDestClasses.remove(destClass);
70 } 69 }
71 matches.remove(match); 70 matches.remove(match);
72 } 71 }
73 72
74 public int size() { 73 public int size() {
75 return matches.size(); 74 return matches.size();
76 } 75 }
77 76
78 @Override 77 @Override
79 public Iterator<ClassMatch> iterator() { 78 public Iterator<ClassMatch> iterator() {
80 return matches.iterator(); 79 return matches.iterator();
81 } 80 }
82 81
83 private void indexMatch(ClassMatch match) { 82 private void indexMatch(ClassMatch match) {
84 if (!match.isMatched()) { 83 if (!match.isMatched()) {
85 // unmatched 84 // unmatched
86 unmatchedSourceClasses.addAll(match.sourceClasses); 85 unmatchedSourceClasses.addAll(match.sourceClasses);
87 unmatchedDestClasses.addAll(match.destClasses); 86 unmatchedDestClasses.addAll(match.destClasses);
88 } else { 87 } else {
89 if (match.isAmbiguous()) { 88 if (match.isAmbiguous()) {
90 // ambiguously matched 89 // ambiguously matched
91 for (ClassEntry entry : match.sourceClasses) { 90 for (ClassEntry entry : match.sourceClasses) {
92 ambiguousMatchesBySource.put(entry, match); 91 ambiguousMatchesBySource.put(entry, match);
93 } 92 }
94 for (ClassEntry entry : match.destClasses) { 93 for (ClassEntry entry : match.destClasses) {
95 ambiguousMatchesByDest.put(entry, match); 94 ambiguousMatchesByDest.put(entry, match);
96 } 95 }
97 } else { 96 } else {
98 // uniquely matched 97 // uniquely matched
99 uniqueMatches.put(match.getUniqueSource(), match.getUniqueDest()); 98 uniqueMatches.put(match.getUniqueSource(), match.getUniqueDest());
100 } 99 }
101 } 100 }
102 for (ClassEntry entry : match.sourceClasses) { 101 for (ClassEntry entry : match.sourceClasses) {
103 matchesBySource.put(entry, match); 102 matchesBySource.put(entry, match);
104 } 103 }
105 for (ClassEntry entry : match.destClasses) { 104 for (ClassEntry entry : match.destClasses) {
106 matchesByDest.put(entry, match); 105 matchesByDest.put(entry, match);
107 } 106 }
108 } 107 }
109 108
110 public BiMap<ClassEntry, ClassEntry> getUniqueMatches() { 109 public BiMap<ClassEntry, ClassEntry> getUniqueMatches() {
111 return uniqueMatches; 110 return uniqueMatches;
112 } 111 }
113 112
114 public Set<ClassEntry> getUnmatchedSourceClasses() { 113 public Set<ClassEntry> getUnmatchedSourceClasses() {
115 return unmatchedSourceClasses; 114 return unmatchedSourceClasses;
116 } 115 }
117 116
118 public Set<ClassEntry> getUnmatchedDestClasses() { 117 public Set<ClassEntry> getUnmatchedDestClasses() {
119 return unmatchedDestClasses; 118 return unmatchedDestClasses;
120 } 119 }
121 120
122 public Set<ClassEntry> getAmbiguouslyMatchedSourceClasses() { 121 public Set<ClassEntry> getAmbiguouslyMatchedSourceClasses() {
123 return ambiguousMatchesBySource.keySet(); 122 return ambiguousMatchesBySource.keySet();
124 } 123 }
125 124
126 public ClassMatch getAmbiguousMatchBySource(ClassEntry sourceClass) { 125 public ClassMatch getAmbiguousMatchBySource(ClassEntry sourceClass) {
127 return ambiguousMatchesBySource.get(sourceClass); 126 return ambiguousMatchesBySource.get(sourceClass);
128 } 127 }
129 128
130 public ClassMatch getMatchBySource(ClassEntry sourceClass) { 129 public ClassMatch getMatchBySource(ClassEntry sourceClass) {
131 return matchesBySource.get(sourceClass); 130 return matchesBySource.get(sourceClass);
132 } 131 }
133 132
134 public ClassMatch getMatchByDest(ClassEntry destClass) { 133 public ClassMatch getMatchByDest(ClassEntry destClass) {
135 return matchesByDest.get(destClass); 134 return matchesByDest.get(destClass);
136 } 135 }
137 136
138 public void removeSource(ClassEntry sourceClass) { 137 public void removeSource(ClassEntry sourceClass) {
139 ClassMatch match = matchesBySource.get(sourceClass); 138 ClassMatch match = matchesBySource.get(sourceClass);
140 if (match != null) { 139 if (match != null) {
141 remove(match); 140 remove(match);
142 match.sourceClasses.remove(sourceClass); 141 match.sourceClasses.remove(sourceClass);
143 if (!match.sourceClasses.isEmpty() || !match.destClasses.isEmpty()) { 142 if (!match.sourceClasses.isEmpty() || !match.destClasses.isEmpty()) {
144 add(match); 143 add(match);
145 } 144 }
146 } 145 }
147 } 146 }
148 147
149 public void removeDest(ClassEntry destClass) { 148 public void removeDest(ClassEntry destClass) {
150 ClassMatch match = matchesByDest.get(destClass); 149 ClassMatch match = matchesByDest.get(destClass);
151 if (match != null) { 150 if (match != null) {
152 remove(match); 151 remove(match);
153 match.destClasses.remove(destClass); 152 match.destClasses.remove(destClass);
154 if (!match.sourceClasses.isEmpty() || !match.destClasses.isEmpty()) { 153 if (!match.sourceClasses.isEmpty() || !match.destClasses.isEmpty()) {
155 add(match); 154 add(match);
156 } 155 }
157 } 156 }
158 } 157 }
159} 158}