View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one or more
3    *  contributor license agreements.  See the NOTICE file distributed with
4    *  this work for additional information regarding copyright ownership.
5    *  The ASF licenses this file to You under the Apache License, Version 2.0
6    *  (the "License"); you may not use this file except in compliance with
7    *  the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.commons.compress.harmony.pack200;
18  
19  /**
20   * Constant pool entry for a method or field.
21   */
22  public class CPMethodOrField extends ConstantPoolEntry implements Comparable {
23  
24      private final CPClass className;
25      private final CPNameAndType nameAndType;
26      private int indexInClass = -1;
27      private int indexInClassForConstructor = -1;
28  
29      public CPMethodOrField(final CPClass className, final CPNameAndType nameAndType) {
30          this.className = className;
31          this.nameAndType = nameAndType;
32      }
33  
34      @Override
35      public int compareTo(final Object obj) {
36          if (obj instanceof CPMethodOrField) {
37              final CPMethodOrField mof = (CPMethodOrField) obj;
38              final int compareName = className.compareTo(mof.className);
39              if (compareName == 0) {
40                  return nameAndType.compareTo(mof.nameAndType);
41              }
42              return compareName;
43          }
44          return 0;
45      }
46  
47      public int getClassIndex() {
48          return className.getIndex();
49      }
50  
51      public CPClass getClassName() {
52          return className;
53      }
54  
55      public CPNameAndType getDesc() {
56          return nameAndType;
57      }
58  
59      public int getDescIndex() {
60          return nameAndType.getIndex();
61      }
62  
63      public int getIndexInClass() {
64          return indexInClass;
65      }
66  
67      public int getIndexInClassForConstructor() {
68          return indexInClassForConstructor;
69      }
70  
71      public void setIndexInClass(final int index) {
72          indexInClass = index;
73      }
74  
75      public void setIndexInClassForConstructor(final int index) {
76          indexInClassForConstructor = index;
77      }
78  
79      @Override
80      public String toString() {
81          return className + ": " + nameAndType;
82      }
83  
84  }