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