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