Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/tools/jdi/IntegerValueImpl.java
38920 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.*;2829public class IntegerValueImpl extends PrimitiveValueImpl30implements IntegerValue {31private int value;3233IntegerValueImpl(VirtualMachine aVm,int aValue) {34super(aVm);3536value = aValue;37}3839public boolean equals(Object obj) {40if ((obj != null) && (obj instanceof IntegerValue)) {41return (value == ((IntegerValue)obj).value()) &&42super.equals(obj);43} else {44return false;45}46}4748public int hashCode() {49/*50* TO DO: Better hash code51*/52return intValue();53}5455public int compareTo(IntegerValue obj) {56int other = obj.value();57return (value()<other ? -1 : (value()==other ? 0 : 1));58}5960public Type type() {61return vm.theIntegerType();62}6364public int value() {65return value;66}6768public boolean booleanValue() {69return(value == 0)?false:true;70}7172public byte byteValue() {73return(byte)value;74}7576public char charValue() {77return(char)value;78}7980public short shortValue() {81return(short)value;82}8384public int intValue() {85return value;86}8788public long longValue() {89return(long)value;90}9192public float floatValue() {93return(float)value;94}9596public double doubleValue() {97return(double)value;98}99100byte checkedByteValue() throws InvalidTypeException {101if ((value > Byte.MAX_VALUE) || (value < Byte.MIN_VALUE)) {102throw new InvalidTypeException("Can't convert " + value + " to byte");103} else {104return super.checkedByteValue();105}106}107108char checkedCharValue() throws InvalidTypeException {109if ((value > Character.MAX_VALUE) || (value < Character.MIN_VALUE)) {110throw new InvalidTypeException("Can't convert " + value + " to char");111} else {112return super.checkedCharValue();113}114}115116short checkedShortValue() throws InvalidTypeException {117if ((value > Short.MAX_VALUE) || (value < Short.MIN_VALUE)) {118throw new InvalidTypeException("Can't convert " + value + " to short");119} else {120return super.checkedShortValue();121}122}123124public String toString() {125return "" + value;126}127128byte typeValueKey() {129return JDWP.Tag.INT;130}131}132133134