From 1ad33bfe0a96b1b4a1f3c02cf2c054e8a101dfd8 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 9 Mar 2015 20:08:15 -0400 Subject: field matcher is starting to be useful --- src/cuchaz/enigma/convert/FieldMatches.java | 69 ++++++++++++++++++++++++----- 1 file changed, 59 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 f78a8f5..6335974 100644 --- a/src/cuchaz/enigma/convert/FieldMatches.java +++ b/src/cuchaz/enigma/convert/FieldMatches.java @@ -5,7 +5,8 @@ import java.util.Set; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -import com.google.common.collect.Sets; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; import cuchaz.enigma.mapping.ClassEntry; import cuchaz.enigma.mapping.FieldEntry; @@ -14,22 +15,70 @@ import cuchaz.enigma.mapping.FieldEntry; public class FieldMatches { private BiMap m_matches; - private Set m_unmatchedSourceFields; + private Multimap m_unmatchedSourceFields; + private Multimap m_unmatchedDestFields; public FieldMatches() { m_matches = HashBiMap.create(); - m_unmatchedSourceFields = Sets.newHashSet(); + m_unmatchedSourceFields = HashMultimap.create(); + m_unmatchedDestFields = HashMultimap.create(); } - public void addUnmatchedSourceFields(Set fieldEntries) { - m_unmatchedSourceFields.addAll(fieldEntries); + public void addMatch(FieldEntry srcField, FieldEntry destField) { + m_matches.put(srcField, destField); } - public Collection getSourceClassesWithUnmatchedFields() { - Set classEntries = Sets.newHashSet(); - for (FieldEntry fieldEntry : m_unmatchedSourceFields) { - classEntries.add(fieldEntry.getClassEntry()); + public void addUnmatchedSourceField(FieldEntry fieldEntry) { + m_unmatchedSourceFields.put(fieldEntry.getClassEntry(), fieldEntry); + } + + public void addUnmatchedSourceFields(Iterable fieldEntries) { + for (FieldEntry fieldEntry : fieldEntries) { + addUnmatchedSourceField(fieldEntry); + } + } + + public void addUnmatchedDestField(FieldEntry fieldEntry) { + m_unmatchedDestFields.put(fieldEntry.getClassEntry(), fieldEntry); + } + + public void addUnmatchedDestFields(Iterable fieldEntries) { + for (FieldEntry fieldEntry : fieldEntries) { + addUnmatchedDestField(fieldEntry); } - return classEntries; + } + + public Set getSourceClassesWithUnmatchedFields() { + return m_unmatchedSourceFields.keySet(); + } + + public Collection getUnmatchedSourceFields() { + return m_unmatchedSourceFields.values(); + } + + public Collection getUnmatchedSourceFields(ClassEntry sourceClass) { + return m_unmatchedSourceFields.get(sourceClass); + } + + public Collection getUnmatchedDestFields() { + return m_unmatchedDestFields.values(); + } + + public Collection getUnmatchedDestFields(ClassEntry sourceClass) { + return m_unmatchedDestFields.get(sourceClass); + } + + public BiMap matches() { + return m_matches; + } + + public boolean isDestMatched(FieldEntry destFieldEntry) { + return m_matches.containsValue(destFieldEntry); + } + + public void makeMatch(FieldEntry sourceField, FieldEntry destField) { + m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); + m_unmatchedDestFields.remove(destField.getClassEntry(), destField); + m_matches.put(sourceField, destField); } } -- cgit v1.2.3