| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package org.apache.commons.compress.harmony.unpack200.bytecode; |
| 20 |
|
| 21 |
import java.io.DataOutputStream; |
| 22 |
import java.io.IOException; |
| 23 |
import java.util.Objects; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class CPClass extends ConstantPoolEntry { |
| 29 |
|
| 30 |
private int index; |
| 31 |
|
| 32 |
public String name; |
| 33 |
|
| 34 |
private final CPUTF8 utf8; |
| 35 |
|
| 36 |
private boolean hashCodeComputed; |
| 37 |
|
| 38 |
private int cachedHashCode; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public CPClass(final CPUTF8 name, final int globalIndex) { |
| 48 |
super(CP_Class, globalIndex); |
| 49 |
this.name = Objects.requireNonNull(name, "name").underlyingString(); |
| 50 |
this.utf8 = name; |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
public boolean equals(final Object obj) { |
| 55 |
if (this == obj) { |
| 56 |
return true; |
| 57 |
} |
| 58 |
if (obj == null || this.getClass() != obj.getClass()) { |
| 59 |
return false; |
| 60 |
} |
| 61 |
final CPClass other = (CPClass) obj; |
| 62 |
return utf8.equals(other.utf8); |
| 63 |
} |
| 64 |
|
| 65 |
private void generateHashCode() { |
| 66 |
hashCodeComputed = true; |
| 67 |
cachedHashCode = utf8.hashCode(); |
| 68 |
} |
| 69 |
|
| 70 |
public String getName() { |
| 71 |
return name; |
| 72 |
} |
| 73 |
|
| 74 |
@Override |
| 75 |
protected ClassFileEntry[] getNestedClassFileEntries() { |
| 76 |
return new ClassFileEntry[] { utf8, }; |
| 77 |
} |
| 78 |
|
| 79 |
@Override |
| 80 |
public int hashCode() { |
| 81 |
if (!hashCodeComputed) { |
| 82 |
generateHashCode(); |
| 83 |
} |
| 84 |
return cachedHashCode; |
| 85 |
} |
| 86 |
|
| 87 |
@Override |
| 88 |
protected void resolve(final ClassConstantPool pool) { |
| 89 |
super.resolve(pool); |
| 90 |
index = pool.indexOf(utf8); |
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
public String toString() { |
| 95 |
return "Class: " + getName(); |
| 96 |
} |
| 97 |
|
| 98 |
@Override |
| 99 |
protected void writeBody(final DataOutputStream dos) throws IOException { |
| 100 |
dos.writeShort(index); |
| 101 |
} |
| 102 |
} |