author | clanger |
Thu, 29 Jun 2017 12:59:55 +0200 | |
changeset 45714 | 1820d351198d |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
11277
diff
changeset
|
2 |
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.jdi; |
|
27 |
||
45714 | 28 |
import com.sun.jdi.IntegerValue; |
29 |
import com.sun.jdi.InvalidTypeException; |
|
30 |
import com.sun.jdi.Type; |
|
31 |
import com.sun.jdi.VirtualMachine; |
|
2 | 32 |
|
33 |
public class IntegerValueImpl extends PrimitiveValueImpl |
|
34 |
implements IntegerValue { |
|
35 |
private int value; |
|
36 |
||
45714 | 37 |
IntegerValueImpl(VirtualMachine aVm, int aValue) { |
2 | 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() { |
|
45714 | 72 |
return (value == 0 ? false : true); |
2 | 73 |
} |
74 |
||
75 |
public byte byteValue() { |
|
45714 | 76 |
return (byte)value; |
2 | 77 |
} |
78 |
||
79 |
public char charValue() { |
|
45714 | 80 |
return (char)value; |
2 | 81 |
} |
82 |
||
83 |
public short shortValue() { |
|
45714 | 84 |
return (short)value; |
2 | 85 |
} |
86 |
||
87 |
public int intValue() { |
|
11277 | 88 |
return value; |
2 | 89 |
} |
90 |
||
91 |
public long longValue() { |
|
45714 | 92 |
return value; |
2 | 93 |
} |
94 |
||
95 |
public float floatValue() { |
|
45714 | 96 |
return value; |
2 | 97 |
} |
98 |
||
99 |
public double doubleValue() { |
|
45714 | 100 |
return value; |
2 | 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 |
} |