diff options
| author | 2017-05-16 00:24:29 +0200 | |
|---|---|---|
| committer | 2017-05-16 00:24:29 +0200 | |
| commit | b280104d2f926ab74772cef2bf1602663cefa312 (patch) | |
| tree | d130c86a30ec5df37b3a9c4bab576e971ae2e664 /src/main/java/cuchaz/enigma/convert/ClassMatches.java | |
| parent | Add offset for Enum constructor arguments (Fix #58) (diff) | |
| download | enigma-fork-b280104d2f926ab74772cef2bf1602663cefa312.tar.gz enigma-fork-b280104d2f926ab74772cef2bf1602663cefa312.tar.xz enigma-fork-b280104d2f926ab74772cef2bf1602663cefa312.zip | |
Remove the converter + some reorganization
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/ClassMatches.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/convert/ClassMatches.java | 158 |
1 files changed, 0 insertions, 158 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 db2c550..0000000 --- a/src/main/java/cuchaz/enigma/convert/ClassMatches.java +++ /dev/null | |||
| @@ -1,158 +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 | |||
| 12 | package cuchaz.enigma.convert; | ||
| 13 | |||
| 14 | import com.google.common.collect.BiMap; | ||
| 15 | import com.google.common.collect.HashBiMap; | ||
| 16 | import com.google.common.collect.Maps; | ||
| 17 | import com.google.common.collect.Sets; | ||
| 18 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 19 | |||
| 20 | import java.util.*; | ||
| 21 | |||
| 22 | public class ClassMatches implements Iterable<ClassMatch> { | ||
| 23 | |||
| 24 | private Collection<ClassMatch> matches; | ||
| 25 | private Map<ClassEntry, ClassMatch> matchesBySource; | ||
| 26 | private Map<ClassEntry, ClassMatch> matchesByDest; | ||
| 27 | private BiMap<ClassEntry, ClassEntry> uniqueMatches; | ||
| 28 | private Map<ClassEntry, ClassMatch> ambiguousMatchesBySource; | ||
| 29 | private Map<ClassEntry, ClassMatch> ambiguousMatchesByDest; | ||
| 30 | private Set<ClassEntry> unmatchedSourceClasses; | ||
| 31 | private Set<ClassEntry> unmatchedDestClasses; | ||
| 32 | |||
| 33 | public ClassMatches() { | ||
| 34 | this(new ArrayList<>()); | ||
| 35 | } | ||
| 36 | |||
| 37 | public ClassMatches(Collection<ClassMatch> matches) { | ||
| 38 | this.matches = matches; | ||
| 39 | matchesBySource = Maps.newHashMap(); | ||
| 40 | matchesByDest = Maps.newHashMap(); | ||
| 41 | uniqueMatches = HashBiMap.create(); | ||
| 42 | ambiguousMatchesBySource = Maps.newHashMap(); | ||
| 43 | ambiguousMatchesByDest = Maps.newHashMap(); | ||
| 44 | unmatchedSourceClasses = Sets.newHashSet(); | ||
| 45 | unmatchedDestClasses = Sets.newHashSet(); | ||
| 46 | |||
| 47 | for (ClassMatch match : matches) { | ||
| 48 | indexMatch(match); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | public void add(ClassMatch match) { | ||
| 53 | matches.add(match); | ||
| 54 | indexMatch(match); | ||
| 55 | } | ||
| 56 | |||
| 57 | public void remove(ClassMatch match) { | ||
| 58 | for (ClassEntry sourceClass : match.sourceClasses) { | ||
| 59 | matchesBySource.remove(sourceClass); | ||
| 60 | uniqueMatches.remove(sourceClass); | ||
| 61 | ambiguousMatchesBySource.remove(sourceClass); | ||
| 62 | unmatchedSourceClasses.remove(sourceClass); | ||
| 63 | } | ||
| 64 | for (ClassEntry destClass : match.destClasses) { | ||
| 65 | matchesByDest.remove(destClass); | ||
| 66 | uniqueMatches.inverse().remove(destClass); | ||
| 67 | ambiguousMatchesByDest.remove(destClass); | ||
| 68 | unmatchedDestClasses.remove(destClass); | ||
| 69 | } | ||
| 70 | matches.remove(match); | ||
| 71 | } | ||
| 72 | |||
| 73 | public int size() { | ||
| 74 | return matches.size(); | ||
| 75 | } | ||
| 76 | |||
| 77 | @Override | ||
| 78 | public Iterator<ClassMatch> iterator() { | ||
| 79 | return matches.iterator(); | ||
| 80 | } | ||
| 81 | |||
| 82 | private void indexMatch(ClassMatch match) { | ||
| 83 | if (!match.isMatched()) { | ||
| 84 | // unmatched | ||
| 85 | unmatchedSourceClasses.addAll(match.sourceClasses); | ||
| 86 | unmatchedDestClasses.addAll(match.destClasses); | ||
| 87 | } else { | ||
| 88 | if (match.isAmbiguous()) { | ||
| 89 | // ambiguously matched | ||
| 90 | for (ClassEntry entry : match.sourceClasses) { | ||
| 91 | ambiguousMatchesBySource.put(entry, match); | ||
| 92 | } | ||
| 93 | for (ClassEntry entry : match.destClasses) { | ||
| 94 | ambiguousMatchesByDest.put(entry, match); | ||
| 95 | } | ||
| 96 | } else { | ||
| 97 | // uniquely matched | ||
| 98 | uniqueMatches.put(match.getUniqueSource(), match.getUniqueDest()); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | for (ClassEntry entry : match.sourceClasses) { | ||
| 102 | matchesBySource.put(entry, match); | ||
| 103 | } | ||
| 104 | for (ClassEntry entry : match.destClasses) { | ||
| 105 | matchesByDest.put(entry, match); | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | public BiMap<ClassEntry, ClassEntry> getUniqueMatches() { | ||
| 110 | return uniqueMatches; | ||
| 111 | } | ||
| 112 | |||
| 113 | public Set<ClassEntry> getUnmatchedSourceClasses() { | ||
| 114 | return unmatchedSourceClasses; | ||
| 115 | } | ||
| 116 | |||
| 117 | public Set<ClassEntry> getUnmatchedDestClasses() { | ||
| 118 | return unmatchedDestClasses; | ||
| 119 | } | ||
| 120 | |||
| 121 | public Set<ClassEntry> getAmbiguouslyMatchedSourceClasses() { | ||
| 122 | return ambiguousMatchesBySource.keySet(); | ||
| 123 | } | ||
| 124 | |||
| 125 | public ClassMatch getAmbiguousMatchBySource(ClassEntry sourceClass) { | ||
| 126 | return ambiguousMatchesBySource.get(sourceClass); | ||
| 127 | } | ||
| 128 | |||
| 129 | public ClassMatch getMatchBySource(ClassEntry sourceClass) { | ||
| 130 | return matchesBySource.get(sourceClass); | ||
| 131 | } | ||
| 132 | |||
| 133 | public ClassMatch getMatchByDest(ClassEntry destClass) { | ||
| 134 | return matchesByDest.get(destClass); | ||
| 135 | } | ||
| 136 | |||
| 137 | public void removeSource(ClassEntry sourceClass) { | ||
| 138 | ClassMatch match = matchesBySource.get(sourceClass); | ||
| 139 | if (match != null) { | ||
| 140 | remove(match); | ||
| 141 | match.sourceClasses.remove(sourceClass); | ||
| 142 | if (!match.sourceClasses.isEmpty() || !match.destClasses.isEmpty()) { | ||
| 143 | add(match); | ||
| 144 | } | ||
| 145 | } | ||
| 146 | } | ||
| 147 | |||
| 148 | public void removeDest(ClassEntry destClass) { | ||
| 149 | ClassMatch match = matchesByDest.get(destClass); | ||
| 150 | if (match != null) { | ||
| 151 | remove(match); | ||
| 152 | match.destClasses.remove(destClass); | ||
| 153 | if (!match.sourceClasses.isEmpty() || !match.destClasses.isEmpty()) { | ||
| 154 | add(match); | ||
| 155 | } | ||
| 156 | } | ||
| 157 | } | ||
| 158 | } | ||