Path: blob/master/src/jdk.jdi/share/classes/com/sun/tools/jdi/IntegerValueImpl.java
41161 views
/*1* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.jdi;2627import com.sun.jdi.IntegerValue;28import com.sun.jdi.InvalidTypeException;29import com.sun.jdi.Type;30import com.sun.jdi.VirtualMachine;3132public class IntegerValueImpl extends PrimitiveValueImpl33implements IntegerValue {34private int value;3536IntegerValueImpl(VirtualMachine aVm, int aValue) {37super(aVm);38value = aValue;39}4041public boolean equals(Object obj) {42if ((obj != null) && (obj instanceof IntegerValue)) {43return (value == ((IntegerValue)obj).value()) &&44super.equals(obj);45} else {46return false;47}48}4950public int hashCode() {51/*52* TO DO: Better hash code53*/54return intValue();55}5657public int compareTo(IntegerValue obj) {58int other = obj.value();59return (value()<other ? -1 : (value()==other ? 0 : 1));60}6162public Type type() {63return vm.theIntegerType();64}6566public int value() {67return value;68}6970public boolean booleanValue() {71return (value == 0 ? false : true);72}7374public byte byteValue() {75return (byte)value;76}7778public char charValue() {79return (char)value;80}8182public short shortValue() {83return (short)value;84}8586public int intValue() {87return value;88}8990public long longValue() {91return value;92}9394public float floatValue() {95return value;96}9798public double doubleValue() {99return value;100}101102byte checkedByteValue() throws InvalidTypeException {103if ((value > Byte.MAX_VALUE) || (value < Byte.MIN_VALUE)) {104throw new InvalidTypeException("Can't convert " + value + " to byte");105} else {106return super.checkedByteValue();107}108}109110char checkedCharValue() throws InvalidTypeException {111if ((value > Character.MAX_VALUE) || (value < Character.MIN_VALUE)) {112throw new InvalidTypeException("Can't convert " + value + " to char");113} else {114return super.checkedCharValue();115}116}117118short checkedShortValue() throws InvalidTypeException {119if ((value > Short.MAX_VALUE) || (value < Short.MIN_VALUE)) {120throw new InvalidTypeException("Can't convert " + value + " to short");121} else {122return super.checkedShortValue();123}124}125126public String toString() {127return "" + value;128}129130byte typeValueKey() {131return JDWP.Tag.INT;132}133}134135136