diff options
| author | 2016-07-04 18:14:22 +1000 | |
|---|---|---|
| committer | 2016-07-04 18:14:22 +1000 | |
| commit | 59e189bef2b5e6d129fb7c2c988ed0b2130e36ac (patch) | |
| tree | 2b638e60905251de85a4917152d6fc39a4112194 /src/main/java/cuchaz/enigma/convert/ClassMatches.java | |
| parent | Fixed Obf Class list order (diff) | |
| download | enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.tar.gz enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.tar.xz enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.zip | |
Reformat
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/ClassMatches.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/convert/ClassMatches.java | 149 |
1 files changed, 0 insertions, 149 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatches.java b/src/main/java/cuchaz/enigma/convert/ClassMatches.java deleted file mode 100644 index 851c082..0000000 --- a/src/main/java/cuchaz/enigma/convert/ClassMatches.java +++ /dev/null | |||
| @@ -1,149 +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 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.convert; | ||
| 12 | |||
| 13 | import com.google.common.collect.BiMap; | ||
| 14 | import com.google.common.collect.HashBiMap; | ||
| 15 | import com.google.common.collect.Maps; | ||
| 16 | import com.google.common.collect.Sets; | ||
| 17 | |||
| 18 | import java.util.*; | ||
| 19 | |||
| 20 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 21 | |||
| 22 | |||
| 23 | public class ClassMatches implements Iterable<ClassMatch> { | ||
| 24 | |||
| 25 | Collection<ClassMatch> m_matches; | ||
| 26 | Map<ClassEntry, ClassMatch> m_matchesBySource; | ||
| 27 | Map<ClassEntry, ClassMatch> m_matchesByDest; | ||
| 28 | BiMap<ClassEntry, ClassEntry> m_uniqueMatches; | ||
| 29 | Map<ClassEntry, ClassMatch> m_ambiguousMatchesBySource; | ||
| 30 | Map<ClassEntry, ClassMatch> m_ambiguousMatchesByDest; | ||
| 31 | Set<ClassEntry> m_unmatchedSourceClasses; | ||
| 32 | Set<ClassEntry> m_unmatchedDestClasses; | ||
| 33 | |||
| 34 | public ClassMatches() { | ||
| 35 | this(new ArrayList<>()); | ||
| 36 | } | ||
| 37 | |||
| 38 | public ClassMatches(Collection<ClassMatch> matches) { | ||
| 39 | m_matches = matches; | ||
| 40 | m_matchesBySource = Maps.newHashMap(); | ||
| 41 | m_matchesByDest = Maps.newHashMap(); | ||
| 42 | m_uniqueMatches = HashBiMap.create(); | ||
| 43 | m_ambiguousMatchesBySource = Maps.newHashMap(); | ||
| 44 | m_ambiguousMatchesByDest = Maps.newHashMap(); | ||
| 45 | m_unmatchedSourceClasses = Sets.newHashSet(); | ||
| 46 | m_unmatchedDestClasses = Sets.newHashSet(); | ||
| 47 | |||
| 48 | matches.forEach(this::indexMatch); | ||
| 49 | } | ||
| 50 | |||
| 51 | public void add(ClassMatch match) { | ||
| 52 | m_matches.add(match); | ||
| 53 | indexMatch(match); | ||
| 54 | } | ||
| 55 | |||
| 56 | public void remove(ClassMatch match) { | ||
| 57 | for (ClassEntry sourceClass : match.sourceClasses) { | ||
| 58 | m_matchesBySource.remove(sourceClass); | ||
| 59 | m_uniqueMatches.remove(sourceClass); | ||
| 60 | m_ambiguousMatchesBySource.remove(sourceClass); | ||
| 61 | m_unmatchedSourceClasses.remove(sourceClass); | ||
| 62 | } | ||
| 63 | for (ClassEntry destClass : match.destClasses) { | ||
| 64 | m_matchesByDest.remove(destClass); | ||
| 65 | m_uniqueMatches.inverse().remove(destClass); | ||
| 66 | m_ambiguousMatchesByDest.remove(destClass); | ||
| 67 | m_unmatchedDestClasses.remove(destClass); | ||
| 68 | } | ||
| 69 | m_matches.remove(match); | ||
| 70 | } | ||
| 71 | |||
| 72 | public int size() { | ||
| 73 | return m_matches.size(); | ||
| 74 | } | ||
| 75 | |||
| 76 | @Override | ||
| 77 | public Iterator<ClassMatch> iterator() { | ||
| 78 | return m_matches.iterator(); | ||
| 79 | } | ||
| 80 | |||
| 81 | private void indexMatch(ClassMatch match) { | ||
| 82 | if (!match.isMatched()) { | ||
| 83 | // unmatched | ||
| 84 | m_unmatchedSourceClasses.addAll(match.sourceClasses); | ||
| 85 | m_unmatchedDestClasses.addAll(match.destClasses); | ||
| 86 | } else { | ||
| 87 | if (match.isAmbiguous()) { | ||
| 88 | // ambiguously matched | ||
| 89 | for (ClassEntry entry : match.sourceClasses) { | ||
| 90 | m_ambiguousMatchesBySource.put(entry, match); | ||
| 91 | } | ||
| 92 | for (ClassEntry entry : match.destClasses) { | ||
| 93 | m_ambiguousMatchesByDest.put(entry, match); | ||
| 94 | } | ||
| 95 | } else { | ||
| 96 | // uniquely matched | ||
| 97 | m_uniqueMatches.put(match.getUniqueSource(), match.getUniqueDest()); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | for (ClassEntry entry : match.sourceClasses) { | ||
| 101 | m_matchesBySource.put(entry, match); | ||
| 102 | } | ||
| 103 | for (ClassEntry entry : match.destClasses) { | ||
| 104 | m_matchesByDest.put(entry, match); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | public BiMap<ClassEntry, ClassEntry> getUniqueMatches() { | ||
| 109 | return m_uniqueMatches; | ||
| 110 | } | ||
| 111 | |||
| 112 | public Set<ClassEntry> getUnmatchedSourceClasses() { | ||
| 113 | return m_unmatchedSourceClasses; | ||
| 114 | } | ||
| 115 | |||
| 116 | public Set<ClassEntry> getUnmatchedDestClasses() { | ||
| 117 | return m_unmatchedDestClasses; | ||
| 118 | } | ||
| 119 | |||
| 120 | public Set<ClassEntry> getAmbiguouslyMatchedSourceClasses() { | ||
| 121 | return m_ambiguousMatchesBySource.keySet(); | ||
| 122 | } | ||
| 123 | |||
| 124 | public ClassMatch getMatchBySource(ClassEntry sourceClass) { | ||
| 125 | return m_matchesBySource.get(sourceClass); | ||
| 126 | } | ||
| 127 | |||
| 128 | public void removeSource(ClassEntry sourceClass) { | ||
| 129 | ClassMatch match = m_matchesBySource.get(sourceClass); | ||
| 130 | if (match != null) { | ||
| 131 | remove(match); | ||
| 132 | match.sourceClasses.remove(sourceClass); | ||
| 133 | if (!match.sourceClasses.isEmpty() || !match.destClasses.isEmpty()) { | ||
| 134 | add(match); | ||
| 135 | } | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | public void removeDest(ClassEntry destClass) { | ||
| 140 | ClassMatch match = m_matchesByDest.get(destClass); | ||
| 141 | if (match != null) { | ||
| 142 | remove(match); | ||
| 143 | match.destClasses.remove(destClass); | ||
| 144 | if (!match.sourceClasses.isEmpty() || !match.destClasses.isEmpty()) { | ||
| 145 | add(match); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | } | ||
| 149 | } | ||