1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * https://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.commons.compress.harmony.unpack200.bytecode;
20
21 import java.util.Objects;
22
23 /**
24 * Abstract superclass for constant pool constant entries such as numbers or Strings
25 */
26 public abstract class CPConstant extends ConstantPoolEntry {
27
28 private final Object value;
29
30 /**
31 * Constructs a new CPConstant.
32 *
33 * @param tag TODO
34 * @param value TODO
35 * @param globalIndex index in CpBands
36 * @throws NullPointerException if value is null
37 */
38 public CPConstant(final byte tag, final Object value, final int globalIndex) {
39 super(tag, globalIndex);
40 this.value = Objects.requireNonNull(value, "value");
41 }
42
43 @Override
44 public boolean equals(final Object obj) {
45 if (this == obj) {
46 return true;
47 }
48 if (obj == null || this.getClass() != obj.getClass()) {
49 return false;
50 }
51 final CPConstant other = (CPConstant) obj;
52 return Objects.equals(value, other.value);
53 }
54
55 /**
56 * Gets the value.
57 *
58 * @return the value.
59 */
60 protected Object getValue() {
61 return value;
62 }
63
64 @Override
65 public int hashCode() {
66 return Objects.hash(value);
67 }
68 }