CLDC 8: Boolean and Byte
This commit is contained in:
parent
33645983ba
commit
27584e8aa2
@ -1,4 +1,54 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
class Boolean {
|
class Boolean
|
||||||
|
implements Comparable<Boolean> {
|
||||||
|
public static final Boolean FALSE = new Boolean(false);
|
||||||
|
|
||||||
|
public static final Boolean TRUE = new Boolean(true);
|
||||||
|
|
||||||
|
private final boolean value;
|
||||||
|
|
||||||
|
public Boolean(boolean value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean(String s) {
|
||||||
|
this(parseBoolean(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean booleanValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(Boolean b) {
|
||||||
|
return value == b.value ? 0 : (value ? 1 : -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
return (obj instanceof Boolean) && (value == ((Boolean)obj).booleanValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return value ? 1231 : 1237;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean parseBoolean(String s) {
|
||||||
|
return "true".equalsIgnoreCase(s) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toString(boolean b) {
|
||||||
|
return String.valueOf(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean valueOf(boolean b) {
|
||||||
|
return (b ? TRUE : FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean valueOf(String s) {
|
||||||
|
return parseBoolean(s) ? TRUE : FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,102 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
class Byte {
|
public final class Byte
|
||||||
|
extends Number
|
||||||
|
implements Comparable<Byte> {
|
||||||
|
|
||||||
|
public static final byte MAX_VALUE = 127;
|
||||||
|
|
||||||
|
public static final byte MIN_VALUE = -128;
|
||||||
|
|
||||||
|
public static final int SIZE = 8;
|
||||||
|
|
||||||
|
private final byte value;
|
||||||
|
|
||||||
|
public Byte(byte value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Byte(String s) throws NumberFormatException {
|
||||||
|
this.value = parseByte(s, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte byteValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(Byte anotherByte) {
|
||||||
|
return this.value - anotherByte.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Byte decode(String nm)
|
||||||
|
throws NumberFormatException {
|
||||||
|
int i = Integer.decode(nm);
|
||||||
|
if (i < MIN_VALUE || i > MAX_VALUE)
|
||||||
|
throw new NumberFormatException();
|
||||||
|
return new Byte((byte)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double doubleValue() {
|
||||||
|
return (double)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
return obj instanceof Byte && value == ((Byte)obj).value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float floatValue() {
|
||||||
|
return (float)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int intValue() {
|
||||||
|
return (int)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long longValue() {
|
||||||
|
return (long)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte parseByte(String s)
|
||||||
|
throws NumberFormatException {
|
||||||
|
return parseByte(s, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte parseByte(String s,
|
||||||
|
int radix)
|
||||||
|
throws NumberFormatException {
|
||||||
|
int i = Integer.parseInt(s, radix);
|
||||||
|
if (i < MIN_VALUE || i > MAX_VALUE)
|
||||||
|
throw new NumberFormatException();
|
||||||
|
return (byte)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short shortValue() {
|
||||||
|
return (short)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return Integer.toString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toString(byte b) {
|
||||||
|
return Integer.toString(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Byte valueOf(byte b) {
|
||||||
|
return new Byte(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Byte valueOf(String s)
|
||||||
|
throws NumberFormatException {
|
||||||
|
return new Byte(Byte.parseByte(s, 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Byte valueOf(String s, int radix)
|
||||||
|
throws NumberFormatException {
|
||||||
|
return new Byte(Byte.parseByte(s, radix));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
public class Number {
|
public abstract class Number {
|
||||||
public byte byteValue() {
|
public byte byteValue() {
|
||||||
return (byte)intValue();
|
return (byte)intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Number() {
|
||||||
|
}
|
||||||
|
|
||||||
public abstract double doubleValue();
|
public abstract double doubleValue();
|
||||||
|
|
||||||
public abstract float floatValue();
|
public abstract float floatValue();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user