|
1 /* |
|
2 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package com.sun.tools.jdi; |
|
27 |
|
28 import com.sun.jdi.IntegerValue; |
|
29 import com.sun.jdi.InvalidTypeException; |
|
30 import com.sun.jdi.Type; |
|
31 import com.sun.jdi.VirtualMachine; |
|
32 |
|
33 public class IntegerValueImpl extends PrimitiveValueImpl |
|
34 implements IntegerValue { |
|
35 private int value; |
|
36 |
|
37 IntegerValueImpl(VirtualMachine aVm, int aValue) { |
|
38 super(aVm); |
|
39 value = aValue; |
|
40 } |
|
41 |
|
42 public boolean equals(Object obj) { |
|
43 if ((obj != null) && (obj instanceof IntegerValue)) { |
|
44 return (value == ((IntegerValue)obj).value()) && |
|
45 super.equals(obj); |
|
46 } else { |
|
47 return false; |
|
48 } |
|
49 } |
|
50 |
|
51 public int hashCode() { |
|
52 /* |
|
53 * TO DO: Better hash code |
|
54 */ |
|
55 return intValue(); |
|
56 } |
|
57 |
|
58 public int compareTo(IntegerValue obj) { |
|
59 int other = obj.value(); |
|
60 return (value()<other ? -1 : (value()==other ? 0 : 1)); |
|
61 } |
|
62 |
|
63 public Type type() { |
|
64 return vm.theIntegerType(); |
|
65 } |
|
66 |
|
67 public int value() { |
|
68 return value; |
|
69 } |
|
70 |
|
71 public boolean booleanValue() { |
|
72 return (value == 0 ? false : true); |
|
73 } |
|
74 |
|
75 public byte byteValue() { |
|
76 return (byte)value; |
|
77 } |
|
78 |
|
79 public char charValue() { |
|
80 return (char)value; |
|
81 } |
|
82 |
|
83 public short shortValue() { |
|
84 return (short)value; |
|
85 } |
|
86 |
|
87 public int intValue() { |
|
88 return value; |
|
89 } |
|
90 |
|
91 public long longValue() { |
|
92 return value; |
|
93 } |
|
94 |
|
95 public float floatValue() { |
|
96 return value; |
|
97 } |
|
98 |
|
99 public double doubleValue() { |
|
100 return value; |
|
101 } |
|
102 |
|
103 byte checkedByteValue() throws InvalidTypeException { |
|
104 if ((value > Byte.MAX_VALUE) || (value < Byte.MIN_VALUE)) { |
|
105 throw new InvalidTypeException("Can't convert " + value + " to byte"); |
|
106 } else { |
|
107 return super.checkedByteValue(); |
|
108 } |
|
109 } |
|
110 |
|
111 char checkedCharValue() throws InvalidTypeException { |
|
112 if ((value > Character.MAX_VALUE) || (value < Character.MIN_VALUE)) { |
|
113 throw new InvalidTypeException("Can't convert " + value + " to char"); |
|
114 } else { |
|
115 return super.checkedCharValue(); |
|
116 } |
|
117 } |
|
118 |
|
119 short checkedShortValue() throws InvalidTypeException { |
|
120 if ((value > Short.MAX_VALUE) || (value < Short.MIN_VALUE)) { |
|
121 throw new InvalidTypeException("Can't convert " + value + " to short"); |
|
122 } else { |
|
123 return super.checkedShortValue(); |
|
124 } |
|
125 } |
|
126 |
|
127 public String toString() { |
|
128 return "" + value; |
|
129 } |
|
130 |
|
131 byte typeValueKey() { |
|
132 return JDWP.Tag.INT; |
|
133 } |
|
134 } |