Path: blob/master/src/jdk.jdi/share/classes/com/sun/tools/jdi/DoubleValueImpl.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.DoubleValue;28import com.sun.jdi.InvalidTypeException;29import com.sun.jdi.Type;30import com.sun.jdi.VirtualMachine;3132public class DoubleValueImpl extends PrimitiveValueImpl33implements DoubleValue {34private double value;3536DoubleValueImpl(VirtualMachine aVm, double aValue) {37super(aVm);38value = aValue;39}4041public boolean equals(Object obj) {42if ((obj != null) && (obj instanceof DoubleValue)) {43return (value == ((DoubleValue)obj).value()) &&44super.equals(obj);45} else {46return false;47}48}4950public int compareTo(DoubleValue obj) {51double other = obj.value();52if (value() < other) {53return -1;54} else if (value() == other) {55return 0;56} else {57return 1;58}59}6061public int hashCode() {62/*63* TO DO: Better hash code64*/65return intValue();66}6768public Type type() {69return vm.theDoubleType();70}7172public double value() {73return value;74}7576public boolean booleanValue() {77return (value == 0.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 (long)value;98}99100public float floatValue() {101return (float)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}139140long checkedLongValue() throws InvalidTypeException {141long longValue = (long)value;142if (longValue != value) {143throw new InvalidTypeException("Can't convert " + value + " to long");144} else {145return super.checkedLongValue();146}147}148149float checkedFloatValue() throws InvalidTypeException {150float floatValue = (float)value;151if (floatValue != value) {152throw new InvalidTypeException("Can't convert " + value + " to float");153} else {154return super.checkedFloatValue();155}156}157158public String toString() {159return "" + value;160}161162byte typeValueKey() {163return JDWP.Tag.DOUBLE;164}165}166167168