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