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 double constant in the constant pool of a class file
25   */
26  public class ConstDouble extends ConstValue {
27      /* The tag value associated with ConstDouble */
28      public static final int MyTag = CONSTANTDouble;
29  
30      /* The value */
31      private double doubleValue;
32  
33      /* public accessors */
34  
35      /***
36       * The tag of this constant entry
37       */
38      public int tag() {
39          return MyTag;
40      }
41  
42      /***
43       * return the value associated with the entry
44       */
45      public double value() {
46          return doubleValue;
47      }
48  
49      /***
50       * Return the descriptor string for the constant type.
51       */
52      public String descriptor() {
53          return "D";
54      }
55  
56      /***
57       * A printable representation
58       */
59      public String toString() {
60          return "CONSTANTDouble(" + indexAsString() + "): " + 
61              "doubleValue(" + Double.toString(doubleValue) + ")";
62      }
63  
64      /***
65       * Compares this instance with another for structural equality.
66       */
67      //@olsen: added method
68      public boolean isEqual(Stack msg, Object obj) {
69          if (!(obj instanceof ConstDouble)) {
70              msg.push("obj/obj.getClass() = "
71                       + (obj == null ? null : obj.getClass()));
72              msg.push("this.getClass() = "
73                       + this.getClass());
74              return false;
75          }
76          ConstDouble other = (ConstDouble)obj;
77  
78          if (!super.isEqual(msg, other)) {
79              return false;
80          }
81  
82          if (this.doubleValue != other.doubleValue) {
83              msg.push(String.valueOf("doubleValue = "
84                                      + other.doubleValue));
85              msg.push(String.valueOf("doubleValue = "
86                                      + this.doubleValue));
87              return false;
88          }
89          return true;
90      }
91  
92      /* 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 */
93  
94      /***
95       * Construct a ConstDouble object 
96       */
97      ConstDouble(double f) {
98          doubleValue = f;
99      }
100 
101     void formatData(DataOutputStream b) throws IOException {
102         b.writeDouble(doubleValue);
103     }
104 
105     static ConstDouble read(DataInputStream input) throws IOException {
106         return new ConstDouble(input.readDouble());
107     }
108 
109     void resolve(ConstantPool p) { }
110 }