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 a float constant in the constant pool of a class file
25   */
26  public class ConstFloat extends ConstValue {
27      /* The tag value associated with ConstFloat */
28      public static final int MyTag = CONSTANTFloat;
29  
30      /* The value */
31      private float floatValue;
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 float value() {
44          return floatValue;
45      }
46  
47      /***
48       * Return the descriptor string for the constant type.
49       */
50      public String descriptor() {
51          return "F";
52      }
53  
54      /***
55       * A printable representation
56       */
57      public String toString() {
58          return "CONSTANTFloat(" + indexAsString() + "): " + 
59              "floatValue(" + Float.toString(floatValue) + ")";
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 ConstFloat)) {
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          ConstFloat other = (ConstFloat)obj;
75  
76          if (!super.isEqual(msg, other)) {
77              return false;
78          }
79  
80          if (this.floatValue != other.floatValue) {
81              msg.push(String.valueOf("floatValue = "
82                                      + other.floatValue));
83              msg.push(String.valueOf("floatValue = "
84                                      + this.floatValue));
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      ConstFloat(float f) {
93          floatValue = f;
94      }
95  
96      void formatData(DataOutputStream b) throws IOException {
97          b.writeFloat(floatValue);
98      }
99  
100     static ConstFloat read(DataInputStream input) throws IOException {
101         return new ConstFloat(input.readFloat());
102     }
103 
104     void resolve(ConstantPool p) { }
105 }