diff options
| author | 2017-03-08 08:17:04 +0100 | |
|---|---|---|
| committer | 2017-03-08 08:17:04 +0100 | |
| commit | 6e464ea251cab63c776ece0b2a356f1498ffa294 (patch) | |
| tree | 5ed30c03f5ac4cd2d6877874f5ede576049954f7 /src/main/java/cuchaz/enigma/convert/ClassNamer.java | |
| parent | Drop unix case style and implement hashCode when equals is overrided (diff) | |
| download | enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.gz enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.xz enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.zip | |
Follow Fabric guidelines
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/ClassNamer.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/convert/ClassNamer.java | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/ClassNamer.java b/src/main/java/cuchaz/enigma/convert/ClassNamer.java index e471c7d..3969910 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassNamer.java +++ b/src/main/java/cuchaz/enigma/convert/ClassNamer.java | |||
| @@ -8,49 +8,48 @@ | |||
| 8 | * Contributors: | 8 | * Contributors: |
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | |||
| 11 | package cuchaz.enigma.convert; | 12 | package cuchaz.enigma.convert; |
| 12 | 13 | ||
| 13 | import com.google.common.collect.BiMap; | 14 | import com.google.common.collect.BiMap; |
| 14 | import com.google.common.collect.Maps; | 15 | import com.google.common.collect.Maps; |
| 16 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 15 | 17 | ||
| 16 | import java.util.Map; | 18 | import java.util.Map; |
| 17 | 19 | ||
| 18 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 19 | |||
| 20 | public class ClassNamer { | 20 | public class ClassNamer { |
| 21 | 21 | ||
| 22 | public interface SidedClassNamer { | 22 | private Map<String, String> sourceNames; |
| 23 | String getName(String name); | 23 | private Map<String, String> destNames; |
| 24 | } | 24 | public ClassNamer(BiMap<ClassEntry, ClassEntry> mappings) { |
| 25 | 25 | // convert the identity mappings to name maps | |
| 26 | private Map<String, String> sourceNames; | 26 | this.sourceNames = Maps.newHashMap(); |
| 27 | private Map<String, String> destNames; | 27 | this.destNames = Maps.newHashMap(); |
| 28 | 28 | int i = 0; | |
| 29 | public ClassNamer(BiMap<ClassEntry, ClassEntry> mappings) { | 29 | for (Map.Entry<ClassEntry, ClassEntry> entry : mappings.entrySet()) { |
| 30 | // convert the identity mappings to name maps | 30 | String name = String.format("M%04d", i++); |
| 31 | this.sourceNames = Maps.newHashMap(); | 31 | this.sourceNames.put(entry.getKey().getName(), name); |
| 32 | this.destNames = Maps.newHashMap(); | 32 | this.destNames.put(entry.getValue().getName(), name); |
| 33 | int i = 0; | 33 | } |
| 34 | for (Map.Entry<ClassEntry, ClassEntry> entry : mappings.entrySet()) { | 34 | } |
| 35 | String name = String.format("M%04d", i++); | 35 | |
| 36 | this.sourceNames.put(entry.getKey().getName(), name); | 36 | public String getSourceName(String name) { |
| 37 | this.destNames.put(entry.getValue().getName(), name); | 37 | return this.sourceNames.get(name); |
| 38 | } | 38 | } |
| 39 | } | 39 | |
| 40 | 40 | public String getDestName(String name) { | |
| 41 | public String getSourceName(String name) { | 41 | return this.destNames.get(name); |
| 42 | return this.sourceNames.get(name); | 42 | } |
| 43 | } | 43 | |
| 44 | 44 | public SidedClassNamer getSourceNamer() { | |
| 45 | public String getDestName(String name) { | 45 | return this::getSourceName; |
| 46 | return this.destNames.get(name); | 46 | } |
| 47 | } | 47 | |
| 48 | 48 | public SidedClassNamer getDestNamer() { | |
| 49 | public SidedClassNamer getSourceNamer() { | 49 | return this::getDestName; |
| 50 | return this::getSourceName; | 50 | } |
| 51 | } | 51 | |
| 52 | 52 | public interface SidedClassNamer { | |
| 53 | public SidedClassNamer getDestNamer() { | 53 | String getName(String name); |
| 54 | return this::getDestName; | 54 | } |
| 55 | } | ||
| 56 | } | 55 | } |