    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 */
    019
    020package org.apache.commons.compress.harmony.unpack200.bytecode;
    021
    022/**
    023 * Interface method reference constant pool entry.
    024 */
    025public class CPInterfaceMethodRef extends CPRef {
    026
    027    private boolean hashCodeComputed;
    028
    029    private int cachedHashCode;
    030
    031    public CPInterfaceMethodRef(final CPClass className, final CPNameAndType descriptor, final int globalIndex) {
    032        super(CP_InterfaceMethodref, className, descriptor, globalIndex);
    033    }
    034
    035    private void generateHashCode() {
    036        hashCodeComputed = true;
    037        final int PRIME = 31;
    038        int result = 1;
    039        result = PRIME * result + className.hashCode();
    040        result = PRIME * result + nameAndType.hashCode();
    041        cachedHashCode = result;
    042    }
    043
    044    @Override
    045    public int hashCode() {
    046        if (!hashCodeComputed) {
    047            generateHashCode();
    048        }
    049        return cachedHashCode;
    050    }
    051
    052    /**
    053     * 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
    054     * count for 2 and all others count for 1.
    055     *
    056     * @return integer count
    057     */
    058    public int invokeInterfaceCount() {
    059        return nameAndType.invokeInterfaceCount();
    060    }
    061
    062}