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.pack200;
020
021/**
022 * Constant pool entry for a method or field.
023 */
024public class CPMethodOrField extends ConstantPoolEntry implements Comparable {
025
026    private final CPClass className;
027    private final CPNameAndType nameAndType;
028    private int indexInClass = -1;
029    private int indexInClassForConstructor = -1;
030
031    public CPMethodOrField(final CPClass className, final CPNameAndType nameAndType) {
032        this.className = className;
033        this.nameAndType = nameAndType;
034    }
035
036    @Override
037    public int compareTo(final Object obj) {
038        if (obj instanceof CPMethodOrField) {
039            final CPMethodOrField mof = (CPMethodOrField) obj;
040            final int compareName = className.compareTo(mof.className);
041            if (compareName == 0) {
042                return nameAndType.compareTo(mof.nameAndType);
043            }
044            return compareName;
045        }
046        return 0;
047    }
048
049    public int getClassIndex() {
050        return className.getIndex();
051    }
052
053    public CPClass getClassName() {
054        return className;
055    }
056
057    public CPNameAndType getDesc() {
058        return nameAndType;
059    }
060
061    public int getDescIndex() {
062        return nameAndType.getIndex();
063    }
064
065    public int getIndexInClass() {
066        return indexInClass;
067    }
068
069    public int getIndexInClassForConstructor() {
070        return indexInClassForConstructor;
071    }
072
073    public void setIndexInClass(final int index) {
074        indexInClass = index;
075    }
076
077    public void setIndexInClassForConstructor(final int index) {
078        indexInClassForConstructor = index;
079    }
080
081    @Override
082    public String toString() {
083        return className + ": " + nameAndType;
084    }
085
086}