diff options
Diffstat (limited to 'src/cuchaz/enigma/convert/ClassNamer.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/ClassNamer.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/convert/ClassNamer.java b/src/cuchaz/enigma/convert/ClassNamer.java new file mode 100644 index 0000000..1cd9665 --- /dev/null +++ b/src/cuchaz/enigma/convert/ClassNamer.java | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.convert; | ||
| 12 | |||
| 13 | import java.util.Map; | ||
| 14 | |||
| 15 | import com.beust.jcommander.internal.Maps; | ||
| 16 | import com.google.common.collect.BiMap; | ||
| 17 | |||
| 18 | public class ClassNamer | ||
| 19 | { | ||
| 20 | public interface SidedClassNamer | ||
| 21 | { | ||
| 22 | String getName( String name ); | ||
| 23 | } | ||
| 24 | |||
| 25 | private Map<String,String> m_sourceNames; | ||
| 26 | private Map<String,String> m_destNames; | ||
| 27 | |||
| 28 | public ClassNamer( BiMap<ClassIdentity,ClassIdentity> mappings ) | ||
| 29 | { | ||
| 30 | // convert the identity mappings to name maps | ||
| 31 | m_sourceNames = Maps.newHashMap(); | ||
| 32 | m_destNames = Maps.newHashMap(); | ||
| 33 | int i = 0; | ||
| 34 | for( Map.Entry<ClassIdentity,ClassIdentity> entry : mappings.entrySet() ) | ||
| 35 | { | ||
| 36 | String name = String.format( "M%04d", i++ ); | ||
| 37 | m_sourceNames.put( entry.getKey().getClassEntry().getName(), name ); | ||
| 38 | m_destNames.put( entry.getValue().getClassEntry().getName(), name ); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | public String getSourceName( String name ) | ||
| 43 | { | ||
| 44 | return m_sourceNames.get( name ); | ||
| 45 | } | ||
| 46 | |||
| 47 | public String getDestName( String name ) | ||
| 48 | { | ||
| 49 | return m_destNames.get( name ); | ||
| 50 | } | ||
| 51 | |||
| 52 | public SidedClassNamer getSourceNamer( ) | ||
| 53 | { | ||
| 54 | return new SidedClassNamer( ) | ||
| 55 | { | ||
| 56 | @Override | ||
| 57 | public String getName( String name ) | ||
| 58 | { | ||
| 59 | return getSourceName( name ); | ||
| 60 | } | ||
| 61 | }; | ||
| 62 | } | ||
| 63 | |||
| 64 | public SidedClassNamer getDestNamer( ) | ||
| 65 | { | ||
| 66 | return new SidedClassNamer( ) | ||
| 67 | { | ||
| 68 | @Override | ||
| 69 | public String getName( String name ) | ||
| 70 | { | ||
| 71 | return getDestName( name ); | ||
| 72 | } | ||
| 73 | }; | ||
| 74 | } | ||
| 75 | } | ||