1 /* Copyright (C) 1998, 1999 Cygnus Solutions
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 * @author Per Bothner <bothner@cygnus.com>
13 * @date April 17, 1998.
15 /* Written using "Java Class Libraries", 2nd edition, plus online
16 * API docs for JDK 1.2 beta from http://www.javasoft.com.
17 * Status: Believed complete and correct.
18 * Includes JDK 1.2 methods.
21 public final class Byte extends Number implements Comparable
25 public final static byte MIN_VALUE = -128;
26 public final static byte MAX_VALUE = 127;
28 // This initialization is seemingly circular, but it is accepted
29 // by javac, and is handled specially by gcc.
30 public static final Class TYPE = byte.class;
32 public Byte(byte value)
37 public Byte(String str)
38 throws NumberFormatException
40 this.value = parseByte(str, 10);
43 public byte byteValue()
48 public short shortValue()
58 public long longValue ()
63 public float floatValue ()
68 public double doubleValue ()
70 return (double) value;
73 public static Byte decode(String str)
74 throws NumberFormatException
76 int i = (Integer.decode(str)).intValue();
77 if (i < MIN_VALUE || i > MAX_VALUE)
78 throw new NumberFormatException();
79 return new Byte((byte) i);
82 public static byte parseByte(String str, int radix)
83 throws NumberFormatException
85 int i = Integer.parseInt(str, radix);
86 if (i < MIN_VALUE || i > MAX_VALUE)
87 throw new NumberFormatException();
91 public static byte parseByte(String str)
92 throws NumberFormatException
94 return parseByte(str, 10);
97 public static Byte valueOf(String str, int radix)
98 throws NumberFormatException
100 return new Byte(parseByte(str, radix));
103 public static Byte valueOf(String str)
104 throws NumberFormatException
106 return valueOf(str, 10);
110 public int compareTo(Byte anotherByte)
112 return this.value - anotherByte.value;
116 public int compareTo(Object o) throws ClassCastException
118 if (o instanceof Byte)
119 return this.value - ((Byte) o).value;
121 throw new ClassCastException();
124 public boolean equals(Object obj)
126 return obj != null && (obj instanceof Byte) && ((Byte)obj).value == value;
129 // Verified that hashCode is returns plain value (see Boolean_1 test).
130 public int hashCode()
135 public String toString()
137 return Integer.toString((int) value);
140 public static String toString(byte value)
142 return Integer.toString((int) value);