    001/*
    002 *  Licensed to the Apache Software Foundation (ASF) under one or more
    003 *  contributor license agreements.  See the NOTICE file distributed with
    004 *  this work for additional information regarding copyright ownership.
    005 *  The ASF licenses this file to You under the Apache License, Version 2.0
    006 *  (the "License"); you may not use this file except in compliance with
    007 *  the License.  You may obtain a copy of the License at
    008 *
    009 *     http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 *  Unless required by applicable law or agreed to in writing, software
    012 *  distributed under the License is distributed on an "AS IS" BASIS,
    013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 *  See the License for the specific language governing permissions and
    015 *  limitations under the License.
    016 */
    017package org.apache.commons.compress.harmony.unpack200.bytecode;
    018
    019import java.io.DataOutputStream;
    020import java.io.IOException;
    021
    022/**
    023 * Abstract superclass for constant pool entries
    024 */
    025public abstract class ConstantPoolEntry extends ClassFileEntry {
    026
    027    public static final byte CP_Class = 7;
    028
    029    public static final byte CP_Double = 6;
    030
    031    public static final byte CP_Fieldref = 9;
    032
    033    public static final byte CP_Float = 4;
    034
    035    public static final byte CP_Integer = 3;
    036
    037    /*
    038     * class MemberRef extends ConstantPoolEntry { private int index; Class(String name) { super(CP_Class); index = pool.indexOf(name); } void
    039     * writeBody(DataOutputStream dos) throws IOException { dos.writeShort(index); } }
    040     */
    041
    042    public static final byte CP_InterfaceMethodref = 11;
    043
    044    public static final byte CP_Long = 5;
    045
    046    public static final byte CP_Methodref = 10;
    047
    048    public static final byte CP_NameAndType = 12;
    049
    050    public static final byte CP_String = 8;
    051
    052    public static final byte CP_UTF8 = 1;
    053
    054    byte tag;
    055
    056    protected int globalIndex;
    057
    058    ConstantPoolEntry(final byte tag, final int globalIndex) {
    059        this.tag = tag;
    060        this.globalIndex = globalIndex;
    061    }
    062
    063    @Override
    064    public void doWrite(final DataOutputStream dos) throws IOException {
    065        dos.writeByte(tag);
    066        writeBody(dos);
    067    }
    068
    069    @Override
    070    public abstract boolean equals(Object obj);
    071
    072    public int getGlobalIndex() {
    073        return globalIndex;
    074    }
    075
    076    public byte getTag() {
    077        return tag;
    078    }
    079
    080    @Override
    081    public abstract int hashCode();
    082
    083    protected abstract void writeBody(DataOutputStream dos) throws IOException;
    084}