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