1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with this 4 * work for additional information regarding copyright ownership. The ASF 5 * licenses this file to You under the Apache License, Version 2.0 (the 6 * "License"); you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law 9 * or agreed to in writing, software distributed under the License is 10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language 12 * governing permissions and limitations under the License. 13 */ 14 package org.apache.commons.compress.harmony.unpack200.bytecode; 15 16 /** 17 * Interface method reference constant pool entry. 18 */ 19 public class CPInterfaceMethodRef extends CPRef { 20 21 private boolean hashCodeComputed; 22 23 private int cachedHashCode; 24 25 public CPInterfaceMethodRef(final CPClass className, final CPNameAndType descriptor, final int globalIndex) { 26 super(CP_InterfaceMethodref, className, descriptor, globalIndex); 27 } 28 29 private void generateHashCode() { 30 hashCodeComputed = true; 31 final int PRIME = 31; 32 int result = 1; 33 result = PRIME * result + className.hashCode(); 34 result = PRIME * result + nameAndType.hashCode(); 35 cachedHashCode = result; 36 } 37 38 @Override 39 public int hashCode() { 40 if (!hashCodeComputed) { 41 generateHashCode(); 42 } 43 return cachedHashCode; 44 } 45 46 /** 47 * 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 48 * count for 2 and all others count for 1. 49 * 50 * @return integer count 51 */ 52 public int invokeInterfaceCount() { 53 return nameAndType.invokeInterfaceCount(); 54 } 55 56 }