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    private boolean hashCodeComputed;
022
023    private int cachedHashCode;
024
025    public CPInterfaceMethodRef(final CPClass className, final CPNameAndType descriptor, final int globalIndex) {
026        super(ConstantPoolEntry.CP_InterfaceMethodref, className, descriptor, globalIndex);
027    }
028    private void generateHashCode() {
029        hashCodeComputed = true;
030        final int PRIME = 31;
031        int result = 1;
032        result = PRIME * result + className.hashCode();
033        result = PRIME * result + nameAndType.hashCode();
034        cachedHashCode = result;
035    }
036
037    @Override
038    public int hashCode() {
039        if (!hashCodeComputed) {
040            generateHashCode();
041        }
042        return cachedHashCode;
043    }
044
045    /**
046     * This method answers the value this method will use for an invokeinterface call. This is equal to 1 + the count of
047     * all the args, where longs and doubles count for 2 and all others count for 1.
048     *
049     * @return integer count
050     */
051    public int invokeInterfaceCount() {
052        return nameAndType.invokeInterfaceCount();
053    }
054
055}