Path: blob/master/src/jdk.jdi/share/classes/com/sun/tools/jdi/CharValueImpl.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.CharValue;28import com.sun.jdi.InvalidTypeException;29import com.sun.jdi.Type;30import com.sun.jdi.VirtualMachine;3132public class CharValueImpl extends PrimitiveValueImpl33implements CharValue34{35private char value;3637CharValueImpl(VirtualMachine aVm, char aValue) {38super(aVm);39value = aValue;40}4142public boolean equals(Object obj) {43if ((obj != null) && (obj instanceof CharValue)) {44return (value == ((CharValue)obj).value()) &&45super.equals(obj);46} else {47return false;48}49}5051public int hashCode() {52/*53* TO DO: Better hash code54*/55return intValue();56}5758public int compareTo(CharValue obj) {59char other = obj.value();60return value() - other;61}6263public Type type() {64return vm.theCharType();65}6667public char value() {68return value;69}7071public boolean booleanValue() {72return (value == 0 ? false : true);73}7475public byte byteValue() {76return (byte)value;77}7879public char charValue() {80return value;81}8283public short shortValue() {84return (short)value;85}8687public int intValue() {88return value;89}9091public long longValue() {92return value;93}9495public float floatValue() {96return value;97}9899public double doubleValue() {100return value;101}102103public String toString() {104return "" + value;105}106107byte checkedByteValue() throws InvalidTypeException {108// Note: since char is unsigned, don't check against MIN_VALUE109if (value > Byte.MAX_VALUE) {110throw new InvalidTypeException("Can't convert " + value + " to byte");111} else {112return super.checkedByteValue();113}114}115116short checkedShortValue() throws InvalidTypeException {117// Note: since char is unsigned, don't check against MIN_VALUE118if (value > Short.MAX_VALUE) {119throw new InvalidTypeException("Can't convert " + value + " to short");120} else {121return super.checkedShortValue();122}123}124125byte typeValueKey() {126return JDWP.Tag.CHAR;127}128}129130131