Path: blob/master/src/jdk.jdi/share/classes/com/sun/tools/jdi/LongValueImpl.java
41161 views
/*1* Copyright (c) 1998, 2017, 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.InvalidTypeException;28import com.sun.jdi.LongValue;29import com.sun.jdi.Type;30import com.sun.jdi.VirtualMachine;3132public class LongValueImpl extends PrimitiveValueImpl33implements LongValue {34private long value;3536LongValueImpl(VirtualMachine aVm, long aValue) {37super(aVm);38value = aValue;39}4041public boolean equals(Object obj) {42if ((obj != null) && (obj instanceof LongValue)) {43return (value == ((LongValue)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(LongValue obj) {58long other = obj.value();59if (value() < other) {60return -1;61} else if (value() == other) {62return 0;63} else {64return 1;65}66}6768public Type type() {69return vm.theLongType();70}7172public long value() {73return value;74}7576public boolean booleanValue() {77return (value == 0 ? false : true);78}7980public byte byteValue() {81return (byte)value;82}8384public char charValue() {85return (char)value;86}8788public short shortValue() {89return (short)value;90}9192public int intValue() {93return (int)value;94}9596public long longValue() {97return value;98}99100public float floatValue() {101return value;102}103104public double doubleValue() {105return value;106}107108byte checkedByteValue() throws InvalidTypeException {109if ((value > Byte.MAX_VALUE) || (value < Byte.MIN_VALUE)) {110throw new InvalidTypeException("Can't convert " + value + " to byte");111} else {112return super.checkedByteValue();113}114}115116char checkedCharValue() throws InvalidTypeException {117if ((value > Character.MAX_VALUE) || (value < Character.MIN_VALUE)) {118throw new InvalidTypeException("Can't convert " + value + " to char");119} else {120return super.checkedCharValue();121}122}123124short checkedShortValue() throws InvalidTypeException {125if ((value > Short.MAX_VALUE) || (value < Short.MIN_VALUE)) {126throw new InvalidTypeException("Can't convert " + value + " to short");127} else {128return super.checkedShortValue();129}130}131132int checkedIntValue() throws InvalidTypeException {133if ((value > Integer.MAX_VALUE) || (value < Integer.MIN_VALUE)) {134throw new InvalidTypeException("Can't convert " + value + " to int");135} else {136return super.checkedIntValue();137}138}139140public String toString() {141return "" + value;142}143144byte typeValueKey() {145return JDWP.Tag.LONG;146}147}148149150