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 String toString() {
036        return className + ": " + nameAndType;
037    }
038
039    @Override
040    public int compareTo(final Object obj) {
041        if (obj instanceof CPMethodOrField) {
042            final CPMethodOrField mof = (CPMethodOrField) obj;
043            final int compareName = className.compareTo(mof.className);
044            if (compareName == 0) {
045                return nameAndType.compareTo(mof.nameAndType);
046            }
047            return compareName;
048        }
049        return 0;
050    }
051
052    public int getClassIndex() {
053        return className.getIndex();
054    }
055
056    public CPClass getClassName() {
057        return className;
058    }
059
060    public int getDescIndex() {
061        return nameAndType.getIndex();
062    }
063
064    public CPNameAndType getDesc() {
065        return nameAndType;
066    }
067
068    public int getIndexInClass() {
069        return indexInClass;
070    }
071
072    public void setIndexInClass(final int index) {
073        indexInClass = index;
074    }
075
076    public int getIndexInClassForConstructor() {
077        return indexInClassForConstructor;
078    }
079
080    public void setIndexInClassForConstructor(final int index) {
081        indexInClassForConstructor = index;
082    }
083
084}