    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one
    003 * or more contributor license agreements.  See the NOTICE file
    004 * distributed with this work for additional information
    005 * regarding copyright ownership.  The ASF licenses this file
    006 * to you under the Apache License, Version 2.0 (the
    007 * "License"); you may not use this file except in compliance
    008 * with the License.  You may obtain a copy of the License at
    009 *
    010 *   https://www.apache.org/licenses/LICENSE-2.0
    011 *
    012 * Unless required by applicable law or agreed to in writing,
    013 * software distributed under the License is distributed on an
    014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015 * KIND, either express or implied.  See the License for the
    016 * specific language governing permissions and limitations
    017 * under the License.
    018 */
    019package org.apache.commons.compress.harmony.unpack200.bytecode;
    020
    021import java.util.Objects;
    022
    023/**
    024 * Abstract superclass for constant pool constant entries such as numbers or Strings
    025 */
    026public abstract class CPConstant extends ConstantPoolEntry {
    027
    028    private final Object value;
    029
    030    /**
    031     * Constructs a new CPConstant.
    032     *
    033     * @param tag         TODO
    034     * @param value       TODO
    035     * @param globalIndex index in CpBands
    036     * @throws NullPointerException if value is null
    037     */
    038    public CPConstant(final byte tag, final Object value, final int globalIndex) {
    039        super(tag, globalIndex);
    040        this.value = Objects.requireNonNull(value, "value");
    041    }
    042
    043    @Override
    044    public boolean equals(final Object obj) {
    045        if (this == obj) {
    046            return true;
    047        }
    048        if (obj == null || this.getClass() != obj.getClass()) {
    049            return false;
    050        }
    051        final CPConstant other = (CPConstant) obj;
    052        return Objects.equals(value, other.value);
    053    }
    054
    055    /**
    056     * Gets the value.
    057     *
    058     * @return the value.
    059     */
    060    protected Object getValue() {
    061        return value;
    062    }
    063
    064    @Override
    065    public int hashCode() {
    066        return Objects.hash(value);
    067    }
    068}