diff options
| author | 2015-02-03 22:00:53 -0500 | |
|---|---|---|
| committer | 2015-02-03 22:00:53 -0500 | |
| commit | 52ab426d8fad3dbee7e728f523a35af94facebda (patch) | |
| tree | 146fadfd8e639a909d6c1d6a193e7eddeab0be4a /src/cuchaz/enigma/mapping/ClassEntry.java | |
| download | enigma-fork-52ab426d8fad3dbee7e728f523a35af94facebda.tar.gz enigma-fork-52ab426d8fad3dbee7e728f523a35af94facebda.tar.xz enigma-fork-52ab426d8fad3dbee7e728f523a35af94facebda.zip | |
oops, don't depend on local procyon project
Diffstat (limited to 'src/cuchaz/enigma/mapping/ClassEntry.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/ClassEntry.java | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/mapping/ClassEntry.java b/src/cuchaz/enigma/mapping/ClassEntry.java new file mode 100644 index 0000000..cf41001 --- /dev/null +++ b/src/cuchaz/enigma/mapping/ClassEntry.java | |||
| @@ -0,0 +1,123 @@ | |||
| 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.mapping; | ||
| 12 | |||
| 13 | import java.io.Serializable; | ||
| 14 | |||
| 15 | public class ClassEntry implements Entry, Serializable { | ||
| 16 | |||
| 17 | private static final long serialVersionUID = 4235460580973955811L; | ||
| 18 | |||
| 19 | private String m_name; | ||
| 20 | |||
| 21 | public ClassEntry(String className) { | ||
| 22 | if (className == null) { | ||
| 23 | throw new IllegalArgumentException("Class name cannot be null!"); | ||
| 24 | } | ||
| 25 | if (className.indexOf('.') >= 0) { | ||
| 26 | throw new IllegalArgumentException("Class name must be in JVM format. ie, path/to/package/class$inner : " + className); | ||
| 27 | } | ||
| 28 | |||
| 29 | m_name = className; | ||
| 30 | |||
| 31 | if (isInnerClass() && getInnerClassName().indexOf('/') >= 0) { | ||
| 32 | throw new IllegalArgumentException("Inner class must not have a package: " + className); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | public ClassEntry(ClassEntry other) { | ||
| 37 | m_name = other.m_name; | ||
| 38 | } | ||
| 39 | |||
| 40 | @Override | ||
| 41 | public String getName() { | ||
| 42 | return m_name; | ||
| 43 | } | ||
| 44 | |||
| 45 | @Override | ||
| 46 | public String getClassName() { | ||
| 47 | return m_name; | ||
| 48 | } | ||
| 49 | |||
| 50 | @Override | ||
| 51 | public ClassEntry getClassEntry() { | ||
| 52 | return this; | ||
| 53 | } | ||
| 54 | |||
| 55 | @Override | ||
| 56 | public ClassEntry cloneToNewClass(ClassEntry classEntry) { | ||
| 57 | return classEntry; | ||
| 58 | } | ||
| 59 | |||
| 60 | @Override | ||
| 61 | public int hashCode() { | ||
| 62 | return m_name.hashCode(); | ||
| 63 | } | ||
| 64 | |||
| 65 | @Override | ||
| 66 | public boolean equals(Object other) { | ||
| 67 | if (other instanceof ClassEntry) { | ||
| 68 | return equals((ClassEntry)other); | ||
| 69 | } | ||
| 70 | return false; | ||
| 71 | } | ||
| 72 | |||
| 73 | public boolean equals(ClassEntry other) { | ||
| 74 | return m_name.equals(other.m_name); | ||
| 75 | } | ||
| 76 | |||
| 77 | @Override | ||
| 78 | public String toString() { | ||
| 79 | return m_name; | ||
| 80 | } | ||
| 81 | |||
| 82 | public boolean isInnerClass() { | ||
| 83 | return m_name.lastIndexOf('$') >= 0; | ||
| 84 | } | ||
| 85 | |||
| 86 | public String getOuterClassName() { | ||
| 87 | if (isInnerClass()) { | ||
| 88 | return m_name.substring(0, m_name.lastIndexOf('$')); | ||
| 89 | } | ||
| 90 | return m_name; | ||
| 91 | } | ||
| 92 | |||
| 93 | public String getInnerClassName() { | ||
| 94 | if (!isInnerClass()) { | ||
| 95 | throw new Error("This is not an inner class!"); | ||
| 96 | } | ||
| 97 | return m_name.substring(m_name.lastIndexOf('$') + 1); | ||
| 98 | } | ||
| 99 | |||
| 100 | public ClassEntry getOuterClassEntry() { | ||
| 101 | return new ClassEntry(getOuterClassName()); | ||
| 102 | } | ||
| 103 | |||
| 104 | public boolean isInDefaultPackage() { | ||
| 105 | return m_name.indexOf('/') < 0; | ||
| 106 | } | ||
| 107 | |||
| 108 | public String getPackageName() { | ||
| 109 | int pos = m_name.lastIndexOf('/'); | ||
| 110 | if (pos > 0) { | ||
| 111 | return m_name.substring(0, pos); | ||
| 112 | } | ||
| 113 | return null; | ||
| 114 | } | ||
| 115 | |||
| 116 | public String getSimpleName() { | ||
| 117 | int pos = m_name.lastIndexOf('/'); | ||
| 118 | if (pos > 0) { | ||
| 119 | return m_name.substring(pos + 1); | ||
| 120 | } | ||
| 121 | return m_name; | ||
| 122 | } | ||
| 123 | } | ||