diff options
| author | 2016-06-30 00:49:21 +1000 | |
|---|---|---|
| committer | 2016-06-30 00:49:21 +1000 | |
| commit | 4be005617b3b8c3578cca07c5d085d12916f0d1d (patch) | |
| tree | db163431f38703e26da417ef05eaea2b27a498b9 /src/cuchaz/enigma/convert/MemberMatches.java | |
| parent | Some small changes to fix idea importing (diff) | |
| download | enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.gz enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.xz enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.zip | |
Json format (#2)
* Added new format
* Fixed bug
* Updated Version
Diffstat (limited to 'src/cuchaz/enigma/convert/MemberMatches.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/MemberMatches.java | 159 |
1 files changed, 0 insertions, 159 deletions
diff --git a/src/cuchaz/enigma/convert/MemberMatches.java b/src/cuchaz/enigma/convert/MemberMatches.java deleted file mode 100644 index 29def15..0000000 --- a/src/cuchaz/enigma/convert/MemberMatches.java +++ /dev/null | |||
| @@ -1,159 +0,0 @@ | |||
| 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 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.convert; | ||
| 12 | |||
| 13 | import java.util.Collection; | ||
| 14 | import java.util.Set; | ||
| 15 | |||
| 16 | import com.google.common.collect.BiMap; | ||
| 17 | import com.google.common.collect.HashBiMap; | ||
| 18 | import com.google.common.collect.HashMultimap; | ||
| 19 | import com.google.common.collect.Multimap; | ||
| 20 | import com.google.common.collect.Sets; | ||
| 21 | |||
| 22 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 23 | import cuchaz.enigma.mapping.Entry; | ||
| 24 | |||
| 25 | |||
| 26 | public class MemberMatches<T extends Entry> { | ||
| 27 | |||
| 28 | private BiMap<T,T> m_matches; | ||
| 29 | private Multimap<ClassEntry,T> m_matchedSourceEntries; | ||
| 30 | private Multimap<ClassEntry,T> m_unmatchedSourceEntries; | ||
| 31 | private Multimap<ClassEntry,T> m_unmatchedDestEntries; | ||
| 32 | private Multimap<ClassEntry,T> m_unmatchableSourceEntries; | ||
| 33 | |||
| 34 | public MemberMatches() { | ||
| 35 | m_matches = HashBiMap.create(); | ||
| 36 | m_matchedSourceEntries = HashMultimap.create(); | ||
| 37 | m_unmatchedSourceEntries = HashMultimap.create(); | ||
| 38 | m_unmatchedDestEntries = HashMultimap.create(); | ||
| 39 | m_unmatchableSourceEntries = HashMultimap.create(); | ||
| 40 | } | ||
| 41 | |||
| 42 | public void addMatch(T srcEntry, T destEntry) { | ||
| 43 | boolean wasAdded = m_matches.put(srcEntry, destEntry) == null; | ||
| 44 | assert (wasAdded); | ||
| 45 | wasAdded = m_matchedSourceEntries.put(srcEntry.getClassEntry(), srcEntry); | ||
| 46 | assert (wasAdded); | ||
| 47 | } | ||
| 48 | |||
| 49 | public void addUnmatchedSourceEntry(T sourceEntry) { | ||
| 50 | boolean wasAdded = m_unmatchedSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry); | ||
| 51 | assert (wasAdded); | ||
| 52 | } | ||
| 53 | |||
| 54 | public void addUnmatchedSourceEntries(Iterable<T> sourceEntries) { | ||
| 55 | for (T sourceEntry : sourceEntries) { | ||
| 56 | addUnmatchedSourceEntry(sourceEntry); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | public void addUnmatchedDestEntry(T destEntry) { | ||
| 61 | boolean wasAdded = m_unmatchedDestEntries.put(destEntry.getClassEntry(), destEntry); | ||
| 62 | assert (wasAdded); | ||
| 63 | } | ||
| 64 | |||
| 65 | public void addUnmatchedDestEntries(Iterable<T> destEntriesntries) { | ||
| 66 | for (T entry : destEntriesntries) { | ||
| 67 | addUnmatchedDestEntry(entry); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | public void addUnmatchableSourceEntry(T sourceEntry) { | ||
| 72 | boolean wasAdded = m_unmatchableSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry); | ||
| 73 | assert (wasAdded); | ||
| 74 | } | ||
| 75 | |||
| 76 | public Set<ClassEntry> getSourceClassesWithUnmatchedEntries() { | ||
| 77 | return m_unmatchedSourceEntries.keySet(); | ||
| 78 | } | ||
| 79 | |||
| 80 | public Collection<ClassEntry> getSourceClassesWithoutUnmatchedEntries() { | ||
| 81 | Set<ClassEntry> out = Sets.newHashSet(); | ||
| 82 | out.addAll(m_matchedSourceEntries.keySet()); | ||
| 83 | out.removeAll(m_unmatchedSourceEntries.keySet()); | ||
| 84 | return out; | ||
| 85 | } | ||
| 86 | |||
| 87 | public Collection<T> getUnmatchedSourceEntries() { | ||
| 88 | return m_unmatchedSourceEntries.values(); | ||
| 89 | } | ||
| 90 | |||
| 91 | public Collection<T> getUnmatchedSourceEntries(ClassEntry sourceClass) { | ||
| 92 | return m_unmatchedSourceEntries.get(sourceClass); | ||
| 93 | } | ||
| 94 | |||
| 95 | public Collection<T> getUnmatchedDestEntries() { | ||
| 96 | return m_unmatchedDestEntries.values(); | ||
| 97 | } | ||
| 98 | |||
| 99 | public Collection<T> getUnmatchedDestEntries(ClassEntry destClass) { | ||
| 100 | return m_unmatchedDestEntries.get(destClass); | ||
| 101 | } | ||
| 102 | |||
| 103 | public Collection<T> getUnmatchableSourceEntries() { | ||
| 104 | return m_unmatchableSourceEntries.values(); | ||
| 105 | } | ||
| 106 | |||
| 107 | public boolean hasSource(T sourceEntry) { | ||
| 108 | return m_matches.containsKey(sourceEntry) || m_unmatchedSourceEntries.containsValue(sourceEntry); | ||
| 109 | } | ||
| 110 | |||
| 111 | public boolean hasDest(T destEntry) { | ||
| 112 | return m_matches.containsValue(destEntry) || m_unmatchedDestEntries.containsValue(destEntry); | ||
| 113 | } | ||
| 114 | |||
| 115 | public BiMap<T,T> matches() { | ||
| 116 | return m_matches; | ||
| 117 | } | ||
| 118 | |||
| 119 | public boolean isMatchedSourceEntry(T sourceEntry) { | ||
| 120 | return m_matches.containsKey(sourceEntry); | ||
| 121 | } | ||
| 122 | |||
| 123 | public boolean isMatchedDestEntry(T destEntry) { | ||
| 124 | return m_matches.containsValue(destEntry); | ||
| 125 | } | ||
| 126 | |||
| 127 | public boolean isUnmatchableSourceEntry(T sourceEntry) { | ||
| 128 | return m_unmatchableSourceEntries.containsEntry(sourceEntry.getClassEntry(), sourceEntry); | ||
| 129 | } | ||
| 130 | |||
| 131 | public void makeMatch(T sourceEntry, T destEntry) { | ||
| 132 | boolean wasRemoved = m_unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); | ||
| 133 | assert (wasRemoved); | ||
| 134 | wasRemoved = m_unmatchedDestEntries.remove(destEntry.getClassEntry(), destEntry); | ||
| 135 | assert (wasRemoved); | ||
| 136 | addMatch(sourceEntry, destEntry); | ||
| 137 | } | ||
| 138 | |||
| 139 | public boolean isMatched(T sourceEntry, T destEntry) { | ||
| 140 | T match = m_matches.get(sourceEntry); | ||
| 141 | return match != null && match.equals(destEntry); | ||
| 142 | } | ||
| 143 | |||
| 144 | public void unmakeMatch(T sourceEntry, T destEntry) { | ||
| 145 | boolean wasRemoved = m_matches.remove(sourceEntry) != null; | ||
| 146 | assert (wasRemoved); | ||
| 147 | wasRemoved = m_matchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); | ||
| 148 | assert (wasRemoved); | ||
| 149 | addUnmatchedSourceEntry(sourceEntry); | ||
| 150 | addUnmatchedDestEntry(destEntry); | ||
| 151 | } | ||
| 152 | |||
| 153 | public void makeSourceUnmatchable(T sourceEntry) { | ||
| 154 | assert(!isMatchedSourceEntry(sourceEntry)); | ||
| 155 | boolean wasRemoved = m_unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); | ||
| 156 | assert (wasRemoved); | ||
| 157 | addUnmatchableSourceEntry(sourceEntry); | ||
| 158 | } | ||
| 159 | } | ||