diff options
Diffstat (limited to 'src/cuchaz/enigma/mapping/ClassEntry.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/ClassEntry.java | 116 |
1 files changed, 45 insertions, 71 deletions
diff --git a/src/cuchaz/enigma/mapping/ClassEntry.java b/src/cuchaz/enigma/mapping/ClassEntry.java index 2c708f2..cf41001 100644 --- a/src/cuchaz/enigma/mapping/ClassEntry.java +++ b/src/cuchaz/enigma/mapping/ClassEntry.java | |||
| @@ -12,137 +12,111 @@ package cuchaz.enigma.mapping; | |||
| 12 | 12 | ||
| 13 | import java.io.Serializable; | 13 | import java.io.Serializable; |
| 14 | 14 | ||
| 15 | 15 | public class ClassEntry implements Entry, Serializable { | |
| 16 | public class ClassEntry implements Entry, Serializable | 16 | |
| 17 | { | ||
| 18 | private static final long serialVersionUID = 4235460580973955811L; | 17 | private static final long serialVersionUID = 4235460580973955811L; |
| 19 | 18 | ||
| 20 | private String m_name; | 19 | private String m_name; |
| 21 | 20 | ||
| 22 | public ClassEntry( String className ) | 21 | public ClassEntry(String className) { |
| 23 | { | 22 | if (className == null) { |
| 24 | if( className == null ) | 23 | throw new IllegalArgumentException("Class name cannot be null!"); |
| 25 | { | ||
| 26 | throw new IllegalArgumentException( "Class name cannot be null!" ); | ||
| 27 | } | 24 | } |
| 28 | if( className.indexOf( '.' ) >= 0 ) | 25 | if (className.indexOf('.') >= 0) { |
| 29 | { | 26 | throw new IllegalArgumentException("Class name must be in JVM format. ie, path/to/package/class$inner : " + className); |
| 30 | throw new IllegalArgumentException( "Class name must be in JVM format. ie, path/to/package/class$inner : " + className ); | ||
| 31 | } | 27 | } |
| 32 | 28 | ||
| 33 | m_name = className; | 29 | m_name = className; |
| 34 | 30 | ||
| 35 | if( isInnerClass() && getInnerClassName().indexOf( '/' ) >= 0 ) | 31 | if (isInnerClass() && getInnerClassName().indexOf('/') >= 0) { |
| 36 | { | 32 | throw new IllegalArgumentException("Inner class must not have a package: " + className); |
| 37 | throw new IllegalArgumentException( "Inner class must not have a package: " + className ); | ||
| 38 | } | 33 | } |
| 39 | } | 34 | } |
| 40 | 35 | ||
| 41 | public ClassEntry( ClassEntry other ) | 36 | public ClassEntry(ClassEntry other) { |
| 42 | { | ||
| 43 | m_name = other.m_name; | 37 | m_name = other.m_name; |
| 44 | } | 38 | } |
| 45 | 39 | ||
| 46 | @Override | 40 | @Override |
| 47 | public String getName( ) | 41 | public String getName() { |
| 48 | { | ||
| 49 | return m_name; | 42 | return m_name; |
| 50 | } | 43 | } |
| 51 | 44 | ||
| 52 | @Override | 45 | @Override |
| 53 | public String getClassName( ) | 46 | public String getClassName() { |
| 54 | { | ||
| 55 | return m_name; | 47 | return m_name; |
| 56 | } | 48 | } |
| 57 | 49 | ||
| 58 | @Override | 50 | @Override |
| 59 | public ClassEntry getClassEntry( ) | 51 | public ClassEntry getClassEntry() { |
| 60 | { | ||
| 61 | return this; | 52 | return this; |
| 62 | } | 53 | } |
| 63 | 54 | ||
| 64 | @Override | 55 | @Override |
| 65 | public ClassEntry cloneToNewClass( ClassEntry classEntry ) | 56 | public ClassEntry cloneToNewClass(ClassEntry classEntry) { |
| 66 | { | ||
| 67 | return classEntry; | 57 | return classEntry; |
| 68 | } | 58 | } |
| 69 | 59 | ||
| 70 | @Override | 60 | @Override |
| 71 | public int hashCode( ) | 61 | public int hashCode() { |
| 72 | { | ||
| 73 | return m_name.hashCode(); | 62 | return m_name.hashCode(); |
| 74 | } | 63 | } |
| 75 | 64 | ||
| 76 | @Override | 65 | @Override |
| 77 | public boolean equals( Object other ) | 66 | public boolean equals(Object other) { |
| 78 | { | 67 | if (other instanceof ClassEntry) { |
| 79 | if( other instanceof ClassEntry ) | 68 | return equals((ClassEntry)other); |
| 80 | { | ||
| 81 | return equals( (ClassEntry)other ); | ||
| 82 | } | 69 | } |
| 83 | return false; | 70 | return false; |
| 84 | } | 71 | } |
| 85 | 72 | ||
| 86 | public boolean equals( ClassEntry other ) | 73 | public boolean equals(ClassEntry other) { |
| 87 | { | 74 | return m_name.equals(other.m_name); |
| 88 | return m_name.equals( other.m_name ); | ||
| 89 | } | 75 | } |
| 90 | 76 | ||
| 91 | @Override | 77 | @Override |
| 92 | public String toString( ) | 78 | public String toString() { |
| 93 | { | ||
| 94 | return m_name; | 79 | return m_name; |
| 95 | } | 80 | } |
| 96 | 81 | ||
| 97 | public boolean isInnerClass( ) | 82 | public boolean isInnerClass() { |
| 98 | { | 83 | return m_name.lastIndexOf('$') >= 0; |
| 99 | return m_name.lastIndexOf( '$' ) >= 0; | ||
| 100 | } | 84 | } |
| 101 | 85 | ||
| 102 | public String getOuterClassName( ) | 86 | public String getOuterClassName() { |
| 103 | { | 87 | if (isInnerClass()) { |
| 104 | if( isInnerClass() ) | 88 | return m_name.substring(0, m_name.lastIndexOf('$')); |
| 105 | { | ||
| 106 | return m_name.substring( 0, m_name.lastIndexOf( '$' ) ); | ||
| 107 | } | 89 | } |
| 108 | return m_name; | 90 | return m_name; |
| 109 | } | 91 | } |
| 110 | 92 | ||
| 111 | public String getInnerClassName( ) | 93 | public String getInnerClassName() { |
| 112 | { | 94 | if (!isInnerClass()) { |
| 113 | if( !isInnerClass() ) | 95 | throw new Error("This is not an inner class!"); |
| 114 | { | ||
| 115 | throw new Error( "This is not an inner class!" ); | ||
| 116 | } | 96 | } |
| 117 | return m_name.substring( m_name.lastIndexOf( '$' ) + 1 ); | 97 | return m_name.substring(m_name.lastIndexOf('$') + 1); |
| 118 | } | 98 | } |
| 119 | 99 | ||
| 120 | public ClassEntry getOuterClassEntry( ) | 100 | public ClassEntry getOuterClassEntry() { |
| 121 | { | 101 | return new ClassEntry(getOuterClassName()); |
| 122 | return new ClassEntry( getOuterClassName() ); | ||
| 123 | } | 102 | } |
| 124 | 103 | ||
| 125 | public boolean isInDefaultPackage( ) | 104 | public boolean isInDefaultPackage() { |
| 126 | { | 105 | return m_name.indexOf('/') < 0; |
| 127 | return m_name.indexOf( '/' ) < 0; | ||
| 128 | } | 106 | } |
| 129 | 107 | ||
| 130 | public String getPackageName( ) | 108 | public String getPackageName() { |
| 131 | { | 109 | int pos = m_name.lastIndexOf('/'); |
| 132 | int pos = m_name.lastIndexOf( '/' ); | 110 | if (pos > 0) { |
| 133 | if( pos > 0 ) | 111 | return m_name.substring(0, pos); |
| 134 | { | ||
| 135 | return m_name.substring( 0, pos ); | ||
| 136 | } | 112 | } |
| 137 | return null; | 113 | return null; |
| 138 | } | 114 | } |
| 139 | 115 | ||
| 140 | public String getSimpleName( ) | 116 | public String getSimpleName() { |
| 141 | { | 117 | int pos = m_name.lastIndexOf('/'); |
| 142 | int pos = m_name.lastIndexOf( '/' ); | 118 | if (pos > 0) { |
| 143 | if( pos > 0 ) | 119 | return m_name.substring(pos + 1); |
| 144 | { | ||
| 145 | return m_name.substring( pos + 1 ); | ||
| 146 | } | 120 | } |
| 147 | return m_name; | 121 | return m_name; |
| 148 | } | 122 | } |