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 name and type pair.
023 */
024public class CPNameAndType extends ConstantPoolEntry implements Comparable {
025
026    private final CPUTF8 name;
027    private final CPSignature signature;
028
029    public CPNameAndType(final CPUTF8 name, final CPSignature signature) {
030        this.name = name;
031        this.signature = signature;
032    }
033
034    @Override
035    public int compareTo(final Object obj) {
036        if (obj instanceof CPNameAndType) {
037            final CPNameAndType nat = (CPNameAndType) obj;
038            final int compareSignature = signature.compareTo(nat.signature);
039            if (compareSignature == 0) {
040                return name.compareTo(nat.name);
041            }
042            return compareSignature;
043        }
044        return 0;
045    }
046
047    public String getName() {
048        return name.getUnderlyingString();
049    }
050
051    public int getNameIndex() {
052        return name.getIndex();
053    }
054
055    public int getTypeIndex() {
056        return signature.getIndex();
057    }
058
059    @Override
060    public String toString() {
061        return name + ":" + signature;
062    }
063
064}