View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  
18  package org.apache.jdo.impl.enhancer.classfile;
19  
20  import java.io.*;
21  import java.util.Stack;
22  
23  /***
24   * Class representing an integer constant in the constant pool of a class file
25   */
26  public class ConstInteger extends ConstValue {
27      /* The tag value associated with ConstInteger */
28      public static final int MyTag = CONSTANTInteger;
29  
30      /* The value */
31      private int intValue;
32  
33      /* public accessors */
34  
35      /***
36       * The tag of this constant entry
37       */
38      public int tag() { return MyTag; }
39  
40      /***
41       * return the value associated with the entry
42       */
43      public int value() {
44          return intValue;
45      }
46  
47      /***
48       * Return the descriptor string for the constant type.
49       */
50      public String descriptor() {
51          return "I";
52      }
53  
54      /***
55       * A printable representation
56       */
57      public String toString() {
58          return "CONSTANTInteger(" + indexAsString() + "): " + 
59              "intValue(" + Integer.toString(intValue) + ")";
60      }
61  
62      /***
63       * Compares this instance with another for structural equality.
64       */
65      //@olsen: added method
66      public boolean isEqual(Stack msg, Object obj) {
67          if (!(obj instanceof ConstInteger)) {
68              msg.push("obj/obj.getClass() = "
69                       + (obj == null ? null : obj.getClass()));
70              msg.push("this.getClass() = "
71                       + this.getClass());
72              return false;
73          }
74          ConstInteger other = (ConstInteger)obj;
75  
76          if (!super.isEqual(msg, other)) {
77              return false;
78          }
79  
80          if (this.intValue != other.intValue) {
81              msg.push(String.valueOf("intValue = "
82                                      + other.intValue));
83              msg.push(String.valueOf("intValue = "
84                                      + this.intValue));
85              return false;
86          }
87          return true;
88      }
89  
90      /* 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 */
91  
92      ConstInteger(int i) {
93          intValue = i;
94      }
95  
96      void formatData(DataOutputStream b) throws IOException {
97          b.writeInt(intValue);
98      }
99  
100     static ConstInteger read(DataInputStream input) throws IOException {
101         return new ConstInteger(input.readInt());
102     }
103 
104     void resolve(ConstantPool p) { }
105 }