Path: blob/master/src/jdk.jdi/share/classes/com/sun/tools/jdi/FloatValueImpl.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.FloatValue;28import com.sun.jdi.InvalidTypeException;29import com.sun.jdi.Type;30import com.sun.jdi.VirtualMachine;3132public class FloatValueImpl extends PrimitiveValueImpl33implements FloatValue {34private float value;3536FloatValueImpl(VirtualMachine aVm, float aValue) {37super(aVm);38value = aValue;39}4041public boolean equals(Object obj) {42if ((obj != null) && (obj instanceof FloatValue)) {43return (value == ((FloatValue)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(FloatValue obj) {58float 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.theFloatType();70}7172public float 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 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 {133int intValue = (int)value;134if (intValue != value) {135throw new InvalidTypeException("Can't convert " + value + " to int");136} else {137return super.checkedIntValue();138}139}140141long checkedLongValue() throws InvalidTypeException {142long longValue = (long)value;143if (longValue != value) {144throw new InvalidTypeException("Can't convert " + value + " to long");145} else {146return super.checkedLongValue();147}148}149150public String toString() {151return "" + value;152}153154byte typeValueKey() {155return JDWP.Tag.FLOAT;156}157}158159160