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/FieldMatches.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/FieldMatches.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/convert/FieldMatches.java | 150 |
1 files changed, 0 insertions, 150 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/FieldMatches.java b/src/main/java/cuchaz/enigma/convert/FieldMatches.java deleted file mode 100644 index a528b27..0000000 --- a/src/main/java/cuchaz/enigma/convert/FieldMatches.java +++ /dev/null | |||
| @@ -1,150 +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.*; | ||
| 15 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 16 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 17 | |||
| 18 | import java.util.Collection; | ||
| 19 | import java.util.Set; | ||
| 20 | |||
| 21 | public class FieldMatches { | ||
| 22 | |||
| 23 | private BiMap<FieldEntry, FieldEntry> matches; | ||
| 24 | private Multimap<ClassEntry, FieldEntry> matchedSourceFields; | ||
| 25 | private Multimap<ClassEntry, FieldEntry> unmatchedSourceFields; | ||
| 26 | private Multimap<ClassEntry, FieldEntry> unmatchedDestFields; | ||
| 27 | private Multimap<ClassEntry, FieldEntry> unmatchableSourceFields; | ||
| 28 | |||
| 29 | public FieldMatches() { | ||
| 30 | matches = HashBiMap.create(); | ||
| 31 | matchedSourceFields = HashMultimap.create(); | ||
| 32 | unmatchedSourceFields = HashMultimap.create(); | ||
| 33 | unmatchedDestFields = HashMultimap.create(); | ||
| 34 | unmatchableSourceFields = HashMultimap.create(); | ||
| 35 | } | ||
| 36 | |||
| 37 | public void addMatch(FieldEntry srcField, FieldEntry destField) { | ||
| 38 | boolean wasAdded = matches.put(srcField, destField) == null; | ||
| 39 | assert (wasAdded); | ||
| 40 | wasAdded = matchedSourceFields.put(srcField.getClassEntry(), srcField); | ||
| 41 | assert (wasAdded); | ||
| 42 | } | ||
| 43 | |||
| 44 | public void addUnmatchedSourceField(FieldEntry fieldEntry) { | ||
| 45 | boolean wasAdded = unmatchedSourceFields.put(fieldEntry.getClassEntry(), fieldEntry); | ||
| 46 | assert (wasAdded); | ||
| 47 | } | ||
| 48 | |||
| 49 | public void addUnmatchedSourceFields(Iterable<FieldEntry> fieldEntries) { | ||
| 50 | for (FieldEntry fieldEntry : fieldEntries) { | ||
| 51 | addUnmatchedSourceField(fieldEntry); | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | public void addUnmatchedDestField(FieldEntry fieldEntry) { | ||
| 56 | boolean wasAdded = unmatchedDestFields.put(fieldEntry.getClassEntry(), fieldEntry); | ||
| 57 | assert (wasAdded); | ||
| 58 | } | ||
| 59 | |||
| 60 | public void addUnmatchedDestFields(Iterable<FieldEntry> fieldEntries) { | ||
| 61 | for (FieldEntry fieldEntry : fieldEntries) { | ||
| 62 | addUnmatchedDestField(fieldEntry); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | public void addUnmatchableSourceField(FieldEntry sourceField) { | ||
| 67 | boolean wasAdded = unmatchableSourceFields.put(sourceField.getClassEntry(), sourceField); | ||
| 68 | assert (wasAdded); | ||
| 69 | } | ||
| 70 | |||
| 71 | public Set<ClassEntry> getSourceClassesWithUnmatchedFields() { | ||
| 72 | return unmatchedSourceFields.keySet(); | ||
| 73 | } | ||
| 74 | |||
| 75 | public Collection<ClassEntry> getSourceClassesWithoutUnmatchedFields() { | ||
| 76 | Set<ClassEntry> out = Sets.newHashSet(); | ||
| 77 | out.addAll(matchedSourceFields.keySet()); | ||
| 78 | out.removeAll(unmatchedSourceFields.keySet()); | ||
| 79 | return out; | ||
| 80 | } | ||
| 81 | |||
| 82 | public Collection<FieldEntry> getUnmatchedSourceFields() { | ||
| 83 | return unmatchedSourceFields.values(); | ||
| 84 | } | ||
| 85 | |||
| 86 | public Collection<FieldEntry> getUnmatchedSourceFields(ClassEntry sourceClass) { | ||
| 87 | return unmatchedSourceFields.get(sourceClass); | ||
| 88 | } | ||
| 89 | |||
| 90 | public Collection<FieldEntry> getUnmatchedDestFields() { | ||
| 91 | return unmatchedDestFields.values(); | ||
| 92 | } | ||
| 93 | |||
| 94 | public Collection<FieldEntry> getUnmatchedDestFields(ClassEntry destClass) { | ||
| 95 | return unmatchedDestFields.get(destClass); | ||
| 96 | } | ||
| 97 | |||
| 98 | public Collection<FieldEntry> getUnmatchableSourceFields() { | ||
| 99 | return unmatchableSourceFields.values(); | ||
| 100 | } | ||
| 101 | |||
| 102 | public boolean hasSource(FieldEntry fieldEntry) { | ||
| 103 | return matches.containsKey(fieldEntry) || unmatchedSourceFields.containsValue(fieldEntry); | ||
| 104 | } | ||
| 105 | |||
| 106 | public boolean hasDest(FieldEntry fieldEntry) { | ||
| 107 | return matches.containsValue(fieldEntry) || unmatchedDestFields.containsValue(fieldEntry); | ||
| 108 | } | ||
| 109 | |||
| 110 | public BiMap<FieldEntry, FieldEntry> matches() { | ||
| 111 | return matches; | ||
| 112 | } | ||
| 113 | |||
| 114 | public boolean isMatchedSourceField(FieldEntry sourceField) { | ||
| 115 | return matches.containsKey(sourceField); | ||
| 116 | } | ||
| 117 | |||
| 118 | public boolean isMatchedDestField(FieldEntry destField) { | ||
| 119 | return matches.containsValue(destField); | ||
| 120 | } | ||
| 121 | |||
| 122 | public void makeMatch(FieldEntry sourceField, FieldEntry destField) { | ||
| 123 | boolean wasRemoved = unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); | ||
| 124 | assert (wasRemoved); | ||
| 125 | wasRemoved = unmatchedDestFields.remove(destField.getClassEntry(), destField); | ||
| 126 | assert (wasRemoved); | ||
| 127 | addMatch(sourceField, destField); | ||
| 128 | } | ||
| 129 | |||
| 130 | public boolean isMatched(FieldEntry sourceField, FieldEntry destField) { | ||
| 131 | FieldEntry match = matches.get(sourceField); | ||
| 132 | return match != null && match.equals(destField); | ||
| 133 | } | ||
| 134 | |||
| 135 | public void unmakeMatch(FieldEntry sourceField, FieldEntry destField) { | ||
| 136 | boolean wasRemoved = matches.remove(sourceField) != null; | ||
| 137 | assert (wasRemoved); | ||
| 138 | wasRemoved = matchedSourceFields.remove(sourceField.getClassEntry(), sourceField); | ||
| 139 | assert (wasRemoved); | ||
| 140 | addUnmatchedSourceField(sourceField); | ||
| 141 | addUnmatchedDestField(destField); | ||
| 142 | } | ||
| 143 | |||
| 144 | public void makeSourceUnmatchable(FieldEntry sourceField) { | ||
| 145 | assert (!isMatchedSourceField(sourceField)); | ||
| 146 | boolean wasRemoved = unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); | ||
| 147 | assert (wasRemoved); | ||
| 148 | addUnmatchableSourceField(sourceField); | ||
| 149 | } | ||
| 150 | } | ||