From 430df87ba5d855ca29bc53a5765a2862d2209098 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 10 Mar 2015 00:55:03 -0400 Subject: tweaks and improvements to field matching gui --- src/cuchaz/enigma/convert/FieldMatches.java | 81 +++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 10 deletions(-) (limited to 'src/cuchaz/enigma/convert/FieldMatches.java') 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; import com.google.common.collect.HashBiMap; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; import cuchaz.enigma.mapping.ClassEntry; import cuchaz.enigma.mapping.FieldEntry; @@ -15,21 +16,29 @@ import cuchaz.enigma.mapping.FieldEntry; public class FieldMatches { private BiMap m_matches; + private Multimap m_matchedSourceFields; private Multimap m_unmatchedSourceFields; private Multimap m_unmatchedDestFields; + private Multimap m_unmatchableSourceFields; public FieldMatches() { m_matches = HashBiMap.create(); + m_matchedSourceFields = HashMultimap.create(); m_unmatchedSourceFields = HashMultimap.create(); m_unmatchedDestFields = HashMultimap.create(); + m_unmatchableSourceFields = HashMultimap.create(); } public void addMatch(FieldEntry srcField, FieldEntry destField) { - m_matches.put(srcField, destField); + boolean wasAdded = m_matches.put(srcField, destField) == null; + assert (wasAdded); + wasAdded = m_matchedSourceFields.put(srcField.getClassEntry(), srcField); + assert (wasAdded); } public void addUnmatchedSourceField(FieldEntry fieldEntry) { - m_unmatchedSourceFields.put(fieldEntry.getClassEntry(), fieldEntry); + boolean wasAdded = m_unmatchedSourceFields.put(fieldEntry.getClassEntry(), fieldEntry); + assert (wasAdded); } public void addUnmatchedSourceFields(Iterable fieldEntries) { @@ -39,7 +48,8 @@ public class FieldMatches { } public void addUnmatchedDestField(FieldEntry fieldEntry) { - m_unmatchedDestFields.put(fieldEntry.getClassEntry(), fieldEntry); + boolean wasAdded = m_unmatchedDestFields.put(fieldEntry.getClassEntry(), fieldEntry); + assert (wasAdded); } public void addUnmatchedDestFields(Iterable fieldEntries) { @@ -48,9 +58,21 @@ public class FieldMatches { } } + public void addUnmatchableSourceField(FieldEntry sourceField) { + boolean wasAdded = m_unmatchableSourceFields.put(sourceField.getClassEntry(), sourceField); + assert (wasAdded); + } + public Set getSourceClassesWithUnmatchedFields() { return m_unmatchedSourceFields.keySet(); } + + public Collection getSourceClassesWithoutUnmatchedFields() { + Set out = Sets.newHashSet(); + out.addAll(m_matchedSourceFields.keySet()); + out.removeAll(m_unmatchedSourceFields.keySet()); + return out; + } public Collection getUnmatchedSourceFields() { return m_unmatchedSourceFields.values(); @@ -64,21 +86,60 @@ public class FieldMatches { return m_unmatchedDestFields.values(); } - public Collection getUnmatchedDestFields(ClassEntry sourceClass) { - return m_unmatchedDestFields.get(sourceClass); + public Collection getUnmatchedDestFields(ClassEntry destClass) { + return m_unmatchedDestFields.get(destClass); + } + + public Collection getUnmatchableSourceFields() { + return m_unmatchableSourceFields.values(); + } + + public boolean hasSource(FieldEntry fieldEntry) { + return m_matches.containsKey(fieldEntry) || m_unmatchedSourceFields.containsValue(fieldEntry); + } + + public boolean hasDest(FieldEntry fieldEntry) { + return m_matches.containsValue(fieldEntry) || m_unmatchedDestFields.containsValue(fieldEntry); } public BiMap matches() { return m_matches; } + + public boolean isMatchedSourceField(FieldEntry sourceField) { + return m_matches.containsKey(sourceField); + } - public boolean isDestMatched(FieldEntry destFieldEntry) { - return m_matches.containsValue(destFieldEntry); + public boolean isMatchedDestField(FieldEntry destField) { + return m_matches.containsValue(destField); } public void makeMatch(FieldEntry sourceField, FieldEntry destField) { - m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); - m_unmatchedDestFields.remove(destField.getClassEntry(), destField); - m_matches.put(sourceField, destField); + boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); + assert (wasRemoved); + wasRemoved = m_unmatchedDestFields.remove(destField.getClassEntry(), destField); + assert (wasRemoved); + addMatch(sourceField, destField); + } + + public boolean isMatched(FieldEntry sourceField, FieldEntry destField) { + FieldEntry match = m_matches.get(sourceField); + return match != null && match.equals(destField); + } + + public void unmakeMatch(FieldEntry sourceField, FieldEntry destField) { + boolean wasRemoved = m_matches.remove(sourceField) != null; + assert (wasRemoved); + wasRemoved = m_matchedSourceFields.remove(sourceField.getClassEntry(), sourceField); + assert (wasRemoved); + addUnmatchedSourceField(sourceField); + addUnmatchedDestField(destField); + } + + public void makeSourceUnmatchable(FieldEntry sourceField) { + assert(!isMatchedSourceField(sourceField)); + boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); + assert (wasRemoved); + addUnmatchableSourceField(sourceField); } } -- cgit v1.2.3