diff options
| author | 2016-08-17 18:35:12 +0200 | |
|---|---|---|
| committer | 2016-08-17 18:35:12 +0200 | |
| commit | 5540c815de36e316d0749ce2163f12c61895b327 (patch) | |
| tree | 2b30d5ae98735ee7cba7d1c0087c51d68ed3ebf9 /src/main/java/cuchaz/enigma/convert/MemberMatches.java | |
| parent | Revert "Removed util" (diff) | |
| download | enigma-fork-5540c815de36e316d0749ce2163f12c61895b327.tar.gz enigma-fork-5540c815de36e316d0749ce2163f12c61895b327.tar.xz enigma-fork-5540c815de36e316d0749ce2163f12c61895b327.zip | |
Revert "Removed unused methods"
This reverts commit 1742190f784d0d62e7cc869eebafdfe1927e448f.
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/MemberMatches.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/convert/MemberMatches.java | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/MemberMatches.java b/src/main/java/cuchaz/enigma/convert/MemberMatches.java new file mode 100644 index 0000000..32850cc --- /dev/null +++ b/src/main/java/cuchaz/enigma/convert/MemberMatches.java | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.convert; | ||
| 12 | |||
| 13 | import com.google.common.collect.*; | ||
| 14 | |||
| 15 | import java.util.Collection; | ||
| 16 | import java.util.Set; | ||
| 17 | |||
| 18 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 19 | import cuchaz.enigma.mapping.Entry; | ||
| 20 | |||
| 21 | |||
| 22 | public class MemberMatches<T extends Entry> { | ||
| 23 | |||
| 24 | private BiMap<T, T> m_matches; | ||
| 25 | private Multimap<ClassEntry, T> m_matchedSourceEntries; | ||
| 26 | private Multimap<ClassEntry, T> m_unmatchedSourceEntries; | ||
| 27 | private Multimap<ClassEntry, T> m_unmatchedDestEntries; | ||
| 28 | private Multimap<ClassEntry, T> m_unmatchableSourceEntries; | ||
| 29 | |||
| 30 | public MemberMatches() { | ||
| 31 | m_matches = HashBiMap.create(); | ||
| 32 | m_matchedSourceEntries = HashMultimap.create(); | ||
| 33 | m_unmatchedSourceEntries = HashMultimap.create(); | ||
| 34 | m_unmatchedDestEntries = HashMultimap.create(); | ||
| 35 | m_unmatchableSourceEntries = HashMultimap.create(); | ||
| 36 | } | ||
| 37 | |||
| 38 | public void addMatch(T srcEntry, T destEntry) { | ||
| 39 | boolean wasAdded = m_matches.put(srcEntry, destEntry) == null; | ||
| 40 | assert (wasAdded); | ||
| 41 | wasAdded = m_matchedSourceEntries.put(srcEntry.getClassEntry(), srcEntry); | ||
| 42 | assert (wasAdded); | ||
| 43 | } | ||
| 44 | |||
| 45 | public void addUnmatchedSourceEntry(T sourceEntry) { | ||
| 46 | boolean wasAdded = m_unmatchedSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry); | ||
| 47 | assert (wasAdded); | ||
| 48 | } | ||
| 49 | |||
| 50 | public void addUnmatchedSourceEntries(Iterable<T> sourceEntries) { | ||
| 51 | for (T sourceEntry : sourceEntries) { | ||
| 52 | addUnmatchedSourceEntry(sourceEntry); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | public void addUnmatchedDestEntry(T destEntry) { | ||
| 57 | boolean wasAdded = m_unmatchedDestEntries.put(destEntry.getClassEntry(), destEntry); | ||
| 58 | assert (wasAdded); | ||
| 59 | } | ||
| 60 | |||
| 61 | public void addUnmatchedDestEntries(Iterable<T> destEntriesntries) { | ||
| 62 | for (T entry : destEntriesntries) { | ||
| 63 | addUnmatchedDestEntry(entry); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | public void addUnmatchableSourceEntry(T sourceEntry) { | ||
| 68 | boolean wasAdded = m_unmatchableSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry); | ||
| 69 | assert (wasAdded); | ||
| 70 | } | ||
| 71 | |||
| 72 | public Set<ClassEntry> getSourceClassesWithUnmatchedEntries() { | ||
| 73 | return m_unmatchedSourceEntries.keySet(); | ||
| 74 | } | ||
| 75 | |||
| 76 | public Collection<ClassEntry> getSourceClassesWithoutUnmatchedEntries() { | ||
| 77 | Set<ClassEntry> out = Sets.newHashSet(); | ||
| 78 | out.addAll(m_matchedSourceEntries.keySet()); | ||
| 79 | out.removeAll(m_unmatchedSourceEntries.keySet()); | ||
| 80 | return out; | ||
| 81 | } | ||
| 82 | |||
| 83 | public Collection<T> getUnmatchedSourceEntries() { | ||
| 84 | return m_unmatchedSourceEntries.values(); | ||
| 85 | } | ||
| 86 | |||
| 87 | public Collection<T> getUnmatchedSourceEntries(ClassEntry sourceClass) { | ||
| 88 | return m_unmatchedSourceEntries.get(sourceClass); | ||
| 89 | } | ||
| 90 | |||
| 91 | public Collection<T> getUnmatchedDestEntries() { | ||
| 92 | return m_unmatchedDestEntries.values(); | ||
| 93 | } | ||
| 94 | |||
| 95 | public Collection<T> getUnmatchedDestEntries(ClassEntry destClass) { | ||
| 96 | return m_unmatchedDestEntries.get(destClass); | ||
| 97 | } | ||
| 98 | |||
| 99 | public Collection<T> getUnmatchableSourceEntries() { | ||
| 100 | return m_unmatchableSourceEntries.values(); | ||
| 101 | } | ||
| 102 | |||
| 103 | public boolean hasSource(T sourceEntry) { | ||
| 104 | return m_matches.containsKey(sourceEntry) || m_unmatchedSourceEntries.containsValue(sourceEntry); | ||
| 105 | } | ||
| 106 | |||
| 107 | public boolean hasDest(T destEntry) { | ||
| 108 | return m_matches.containsValue(destEntry) || m_unmatchedDestEntries.containsValue(destEntry); | ||
| 109 | } | ||
| 110 | |||
| 111 | public BiMap<T, T> matches() { | ||
| 112 | return m_matches; | ||
| 113 | } | ||
| 114 | |||
| 115 | public boolean isMatchedSourceEntry(T sourceEntry) { | ||
| 116 | return m_matches.containsKey(sourceEntry); | ||
| 117 | } | ||
| 118 | |||
| 119 | public boolean isMatchedDestEntry(T destEntry) { | ||
| 120 | return m_matches.containsValue(destEntry); | ||
| 121 | } | ||
| 122 | |||
| 123 | public boolean isUnmatchableSourceEntry(T sourceEntry) { | ||
| 124 | return m_unmatchableSourceEntries.containsEntry(sourceEntry.getClassEntry(), sourceEntry); | ||
| 125 | } | ||
| 126 | |||
| 127 | public void makeMatch(T sourceEntry, T destEntry) { | ||
| 128 | boolean wasRemoved = m_unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); | ||
| 129 | assert (wasRemoved); | ||
| 130 | wasRemoved = m_unmatchedDestEntries.remove(destEntry.getClassEntry(), destEntry); | ||
| 131 | assert (wasRemoved); | ||
| 132 | addMatch(sourceEntry, destEntry); | ||
| 133 | } | ||
| 134 | |||
| 135 | public boolean isMatched(T sourceEntry, T destEntry) { | ||
| 136 | T match = m_matches.get(sourceEntry); | ||
| 137 | return match != null && match.equals(destEntry); | ||
| 138 | } | ||
| 139 | |||
| 140 | public void unmakeMatch(T sourceEntry, T destEntry) { | ||
| 141 | boolean wasRemoved = m_matches.remove(sourceEntry) != null; | ||
| 142 | assert (wasRemoved); | ||
| 143 | wasRemoved = m_matchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); | ||
| 144 | assert (wasRemoved); | ||
| 145 | addUnmatchedSourceEntry(sourceEntry); | ||
| 146 | addUnmatchedDestEntry(destEntry); | ||
| 147 | } | ||
| 148 | |||
| 149 | public void makeSourceUnmatchable(T sourceEntry) { | ||
| 150 | assert (!isMatchedSourceEntry(sourceEntry)); | ||
| 151 | boolean wasRemoved = m_unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); | ||
| 152 | assert (wasRemoved); | ||
| 153 | addUnmatchableSourceEntry(sourceEntry); | ||
| 154 | } | ||
| 155 | } | ||