diff options
| author | 2015-03-10 00:55:03 -0400 | |
|---|---|---|
| committer | 2015-03-10 00:55:03 -0400 | |
| commit | 430df87ba5d855ca29bc53a5765a2862d2209098 (patch) | |
| tree | ee427f009da8b29e7a66a4b4ce882120f9bb2cbf /src/cuchaz/enigma/convert/FieldMatches.java | |
| parent | field matcher is starting to be useful (diff) | |
| download | enigma-fork-430df87ba5d855ca29bc53a5765a2862d2209098.tar.gz enigma-fork-430df87ba5d855ca29bc53a5765a2862d2209098.tar.xz enigma-fork-430df87ba5d855ca29bc53a5765a2862d2209098.zip | |
tweaks and improvements to field matching gui
Diffstat (limited to 'src/cuchaz/enigma/convert/FieldMatches.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/FieldMatches.java | 81 |
1 files changed, 71 insertions, 10 deletions
diff --git a/src/cuchaz/enigma/convert/FieldMatches.java b/src/cuchaz/enigma/convert/FieldMatches.java index 6335974..2973356 100644 --- a/src/cuchaz/enigma/convert/FieldMatches.java +++ b/src/cuchaz/enigma/convert/FieldMatches.java | |||
| @@ -7,6 +7,7 @@ import com.google.common.collect.BiMap; | |||
| 7 | import com.google.common.collect.HashBiMap; | 7 | import com.google.common.collect.HashBiMap; |
| 8 | import com.google.common.collect.HashMultimap; | 8 | import com.google.common.collect.HashMultimap; |
| 9 | import com.google.common.collect.Multimap; | 9 | import com.google.common.collect.Multimap; |
| 10 | import com.google.common.collect.Sets; | ||
| 10 | 11 | ||
| 11 | import cuchaz.enigma.mapping.ClassEntry; | 12 | import cuchaz.enigma.mapping.ClassEntry; |
| 12 | import cuchaz.enigma.mapping.FieldEntry; | 13 | import cuchaz.enigma.mapping.FieldEntry; |
| @@ -15,21 +16,29 @@ import cuchaz.enigma.mapping.FieldEntry; | |||
| 15 | public class FieldMatches { | 16 | public class FieldMatches { |
| 16 | 17 | ||
| 17 | private BiMap<FieldEntry,FieldEntry> m_matches; | 18 | private BiMap<FieldEntry,FieldEntry> m_matches; |
| 19 | private Multimap<ClassEntry,FieldEntry> m_matchedSourceFields; | ||
| 18 | private Multimap<ClassEntry,FieldEntry> m_unmatchedSourceFields; | 20 | private Multimap<ClassEntry,FieldEntry> m_unmatchedSourceFields; |
| 19 | private Multimap<ClassEntry,FieldEntry> m_unmatchedDestFields; | 21 | private Multimap<ClassEntry,FieldEntry> m_unmatchedDestFields; |
| 22 | private Multimap<ClassEntry,FieldEntry> m_unmatchableSourceFields; | ||
| 20 | 23 | ||
| 21 | public FieldMatches() { | 24 | public FieldMatches() { |
| 22 | m_matches = HashBiMap.create(); | 25 | m_matches = HashBiMap.create(); |
| 26 | m_matchedSourceFields = HashMultimap.create(); | ||
| 23 | m_unmatchedSourceFields = HashMultimap.create(); | 27 | m_unmatchedSourceFields = HashMultimap.create(); |
| 24 | m_unmatchedDestFields = HashMultimap.create(); | 28 | m_unmatchedDestFields = HashMultimap.create(); |
| 29 | m_unmatchableSourceFields = HashMultimap.create(); | ||
| 25 | } | 30 | } |
| 26 | 31 | ||
| 27 | public void addMatch(FieldEntry srcField, FieldEntry destField) { | 32 | public void addMatch(FieldEntry srcField, FieldEntry destField) { |
| 28 | m_matches.put(srcField, destField); | 33 | boolean wasAdded = m_matches.put(srcField, destField) == null; |
| 34 | assert (wasAdded); | ||
| 35 | wasAdded = m_matchedSourceFields.put(srcField.getClassEntry(), srcField); | ||
| 36 | assert (wasAdded); | ||
| 29 | } | 37 | } |
| 30 | 38 | ||
| 31 | public void addUnmatchedSourceField(FieldEntry fieldEntry) { | 39 | public void addUnmatchedSourceField(FieldEntry fieldEntry) { |
| 32 | m_unmatchedSourceFields.put(fieldEntry.getClassEntry(), fieldEntry); | 40 | boolean wasAdded = m_unmatchedSourceFields.put(fieldEntry.getClassEntry(), fieldEntry); |
| 41 | assert (wasAdded); | ||
| 33 | } | 42 | } |
| 34 | 43 | ||
| 35 | public void addUnmatchedSourceFields(Iterable<FieldEntry> fieldEntries) { | 44 | public void addUnmatchedSourceFields(Iterable<FieldEntry> fieldEntries) { |
| @@ -39,7 +48,8 @@ public class FieldMatches { | |||
| 39 | } | 48 | } |
| 40 | 49 | ||
| 41 | public void addUnmatchedDestField(FieldEntry fieldEntry) { | 50 | public void addUnmatchedDestField(FieldEntry fieldEntry) { |
| 42 | m_unmatchedDestFields.put(fieldEntry.getClassEntry(), fieldEntry); | 51 | boolean wasAdded = m_unmatchedDestFields.put(fieldEntry.getClassEntry(), fieldEntry); |
| 52 | assert (wasAdded); | ||
| 43 | } | 53 | } |
| 44 | 54 | ||
| 45 | public void addUnmatchedDestFields(Iterable<FieldEntry> fieldEntries) { | 55 | public void addUnmatchedDestFields(Iterable<FieldEntry> fieldEntries) { |
| @@ -48,9 +58,21 @@ public class FieldMatches { | |||
| 48 | } | 58 | } |
| 49 | } | 59 | } |
| 50 | 60 | ||
| 61 | public void addUnmatchableSourceField(FieldEntry sourceField) { | ||
| 62 | boolean wasAdded = m_unmatchableSourceFields.put(sourceField.getClassEntry(), sourceField); | ||
| 63 | assert (wasAdded); | ||
| 64 | } | ||
| 65 | |||
| 51 | public Set<ClassEntry> getSourceClassesWithUnmatchedFields() { | 66 | public Set<ClassEntry> getSourceClassesWithUnmatchedFields() { |
| 52 | return m_unmatchedSourceFields.keySet(); | 67 | return m_unmatchedSourceFields.keySet(); |
| 53 | } | 68 | } |
| 69 | |||
| 70 | public Collection<ClassEntry> getSourceClassesWithoutUnmatchedFields() { | ||
| 71 | Set<ClassEntry> out = Sets.newHashSet(); | ||
| 72 | out.addAll(m_matchedSourceFields.keySet()); | ||
| 73 | out.removeAll(m_unmatchedSourceFields.keySet()); | ||
| 74 | return out; | ||
| 75 | } | ||
| 54 | 76 | ||
| 55 | public Collection<FieldEntry> getUnmatchedSourceFields() { | 77 | public Collection<FieldEntry> getUnmatchedSourceFields() { |
| 56 | return m_unmatchedSourceFields.values(); | 78 | return m_unmatchedSourceFields.values(); |
| @@ -64,21 +86,60 @@ public class FieldMatches { | |||
| 64 | return m_unmatchedDestFields.values(); | 86 | return m_unmatchedDestFields.values(); |
| 65 | } | 87 | } |
| 66 | 88 | ||
| 67 | public Collection<FieldEntry> getUnmatchedDestFields(ClassEntry sourceClass) { | 89 | public Collection<FieldEntry> getUnmatchedDestFields(ClassEntry destClass) { |
| 68 | return m_unmatchedDestFields.get(sourceClass); | 90 | return m_unmatchedDestFields.get(destClass); |
| 91 | } | ||
| 92 | |||
| 93 | public Collection<FieldEntry> getUnmatchableSourceFields() { | ||
| 94 | return m_unmatchableSourceFields.values(); | ||
| 95 | } | ||
| 96 | |||
| 97 | public boolean hasSource(FieldEntry fieldEntry) { | ||
| 98 | return m_matches.containsKey(fieldEntry) || m_unmatchedSourceFields.containsValue(fieldEntry); | ||
| 99 | } | ||
| 100 | |||
| 101 | public boolean hasDest(FieldEntry fieldEntry) { | ||
| 102 | return m_matches.containsValue(fieldEntry) || m_unmatchedDestFields.containsValue(fieldEntry); | ||
| 69 | } | 103 | } |
| 70 | 104 | ||
| 71 | public BiMap<FieldEntry,FieldEntry> matches() { | 105 | public BiMap<FieldEntry,FieldEntry> matches() { |
| 72 | return m_matches; | 106 | return m_matches; |
| 73 | } | 107 | } |
| 108 | |||
| 109 | public boolean isMatchedSourceField(FieldEntry sourceField) { | ||
| 110 | return m_matches.containsKey(sourceField); | ||
| 111 | } | ||
| 74 | 112 | ||
| 75 | public boolean isDestMatched(FieldEntry destFieldEntry) { | 113 | public boolean isMatchedDestField(FieldEntry destField) { |
| 76 | return m_matches.containsValue(destFieldEntry); | 114 | return m_matches.containsValue(destField); |
| 77 | } | 115 | } |
| 78 | 116 | ||
| 79 | public void makeMatch(FieldEntry sourceField, FieldEntry destField) { | 117 | public void makeMatch(FieldEntry sourceField, FieldEntry destField) { |
| 80 | m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); | 118 | boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); |
| 81 | m_unmatchedDestFields.remove(destField.getClassEntry(), destField); | 119 | assert (wasRemoved); |
| 82 | m_matches.put(sourceField, destField); | 120 | wasRemoved = m_unmatchedDestFields.remove(destField.getClassEntry(), destField); |
| 121 | assert (wasRemoved); | ||
| 122 | addMatch(sourceField, destField); | ||
| 123 | } | ||
| 124 | |||
| 125 | public boolean isMatched(FieldEntry sourceField, FieldEntry destField) { | ||
| 126 | FieldEntry match = m_matches.get(sourceField); | ||
| 127 | return match != null && match.equals(destField); | ||
| 128 | } | ||
| 129 | |||
| 130 | public void unmakeMatch(FieldEntry sourceField, FieldEntry destField) { | ||
| 131 | boolean wasRemoved = m_matches.remove(sourceField) != null; | ||
| 132 | assert (wasRemoved); | ||
| 133 | wasRemoved = m_matchedSourceFields.remove(sourceField.getClassEntry(), sourceField); | ||
| 134 | assert (wasRemoved); | ||
| 135 | addUnmatchedSourceField(sourceField); | ||
| 136 | addUnmatchedDestField(destField); | ||
| 137 | } | ||
| 138 | |||
| 139 | public void makeSourceUnmatchable(FieldEntry sourceField) { | ||
| 140 | assert(!isMatchedSourceField(sourceField)); | ||
| 141 | boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); | ||
| 142 | assert (wasRemoved); | ||
| 143 | addUnmatchableSourceField(sourceField); | ||
| 83 | } | 144 | } |
| 84 | } | 145 | } |