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  
18  
19  package org.apache.jdo.impl.enhancer.classfile;
20  
21  import java.io.*;
22  import java.util.Stack;
23  
24  /***
25   * Class representing an integer constant in the constant pool of a class file
26   */
27  public class ConstInteger extends ConstValue {
28      /* The tag value associated with ConstInteger */
29      public static final int MyTag = CONSTANTInteger;
30  
31      /* The value */
32      private int intValue;
33  
34      /* public accessors */
35  
36      /***
37       * The tag of this constant entry
38       */
39      public int tag() { return MyTag; }
40  
41      /***
42       * return the value associated with the entry
43       */
44      public int value() {
45          return intValue;
46      }
47  
48      /***
49       * Return the descriptor string for the constant type.
50       */
51      public String descriptor() {
52          return "I";
53      }
54  
55      /***
56       * A printable representation
57       */
58      public String toString() {
59          return "CONSTANTInteger(" + indexAsString() + "): " + 
60              "intValue(" + Integer.toString(intValue) + ")";
61      }
62  
63      /***
64       * Compares this instance with another for structural equality.
65       */
66      //@olsen: added method
67      public boolean isEqual(Stack msg, Object obj) {
68          if (!(obj instanceof ConstInteger)) {
69              msg.push("obj/obj.getClass() = "
70                       + (obj == null ? null : obj.getClass()));
71              msg.push("this.getClass() = "
72                       + this.getClass());
73              return false;
74          }
75          ConstInteger other = (ConstInteger)obj;
76  
77          if (!super.isEqual(msg, other)) {
78              return false;
79          }
80  
81          if (this.intValue != other.intValue) {
82              msg.push(String.valueOf("intValue = "
83                                      + other.intValue));
84              msg.push(String.valueOf("intValue = "
85                                      + this.intValue));
86              return false;
87          }
88          return true;
89      }
90  
91      /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">/* package local methods *//package-summary.html">class="comment"> package local methods */
92  
93      ConstInteger(int i) {
94          intValue = i;
95      }
96  
97      void formatData(DataOutputStream b) throws IOException {
98          b.writeInt(intValue);
99      }
100 
101     static ConstInteger read(DataInputStream input) throws IOException {
102         return new ConstInteger(input.readInt());
103     }
104 
105     void resolve(ConstantPool p) { }
106 }