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