001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with this
004 * work for additional information regarding copyright ownership. The ASF
005 * licenses this file to You under the Apache License, Version 2.0 (the
006 * "License"); you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
009 * or agreed to in writing, software distributed under the License is
010 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
011 * KIND, either express or implied. See the License for the specific language
012 * governing permissions and limitations under the License.
013 */
014package org.apache.commons.compress.harmony.unpack200.bytecode;
015
016/**
017 * Interface method reference constant pool entry.
018 */
019public class CPInterfaceMethodRef extends CPRef {
020
021    public CPInterfaceMethodRef(final CPClass className, final CPNameAndType descriptor, final int globalIndex) {
022        super(ConstantPoolEntry.CP_InterfaceMethodref, className, descriptor, globalIndex);
023    }
024
025    /**
026     * This method answers the value this method will use for an invokeinterface call. This is equal to 1 + the count of
027     * all the args, where longs and doubles count for 2 and all others count for 1.
028     *
029     * @return integer count
030     */
031    public int invokeInterfaceCount() {
032        return nameAndType.invokeInterfaceCount();
033    }
034
035    private boolean hashcodeComputed;
036    private int cachedHashCode;
037
038    private void generateHashCode() {
039        hashcodeComputed = true;
040        final int PRIME = 31;
041        int result = 1;
042        result = PRIME * result + className.hashCode();
043        result = PRIME * result + nameAndType.hashCode();
044        cachedHashCode = result;
045    }
046
047    @Override
048    public int hashCode() {
049        if (!hashcodeComputed) {
050            generateHashCode();
051        }
052        return cachedHashCode;
053    }
054
055}