add additional methods and fields to class library

This commit is contained in:
Joel Dice 2008-03-20 18:40:18 -06:00
parent 8e1ec5794f
commit 7dd9b96717
6 changed files with 57 additions and 10 deletions

View File

@ -21,6 +21,10 @@ public class ByteArrayInputStream extends InputStream {
this.limit = offset + length;
}
public ByteArrayInputStream(byte[] array) {
this(array, 0, array.length);
}
public int read() {
if (position < limit) {
return array[position++] & 0xff;

View File

@ -52,5 +52,17 @@ public abstract class InputStream {
return 0;
}
public void mark(int limit) {
// ignore
}
public void reset() throws IOException {
// ignore
}
public boolean markSupported() {
return false;
}
public void close() throws IOException { }
}

View File

@ -11,6 +11,9 @@
package java.lang;
public final class Character implements Comparable<Character> {
public static final int MIN_RADIX = 2;
public static final int MAX_RADIX = 36;
public static final Class TYPE = Class.forCanonicalName("C");
private final char value;
@ -67,6 +70,23 @@ public final class Character implements Comparable<Character> {
return c >= '0' && c <= '9';
}
public static int digit(char c, int radix) {
int digit = 0;
if ((c >= '0') && (c <= '9')) {
digit = c - '0';
} else if ((c >= 'a') && (c <= 'z')) {
digit = c - 'a' + 10;
} else {
return -1;
}
if (digit < radix) {
return digit;
} else {
return -1;
}
}
public static boolean isLetter(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}

View File

@ -58,6 +58,10 @@ public final class Integer extends Number implements Comparable<Integer> {
return Long.toString(((long) v) & 0xFFFFFFFFL, 16);
}
public static String toBinaryString(int v) {
return Long.toString(((long) v) & 0xFFFFFFFFL, 2);
}
public byte byteValue() {
return (byte) value;
}

View File

@ -11,8 +11,10 @@
package java.lang;
public final class Long extends Number implements Comparable<Long> {
public static final Long MIN_VALUE = -9223372036854775808l;
public static final Long MAX_VALUE = 9223372036854775807l;
public static final Class TYPE = Class.forCanonicalName("J");
public static final Long MAX_VALUE = 9223372036854775807l;
private final long value;
@ -131,16 +133,13 @@ public final class Long extends Number implements Comparable<Long> {
for (; i < s.length(); ++i) {
char c = s.charAt(i);
if (((c >= '0') && (c <= '9')) ||
((c >= 'a') && (c <= 'z'))) {
long digit = ((c >= '0' && c <= '9') ? (c - '0') : (c - 'a' + 10));
if (digit < radix) {
number += digit * pow(radix, (s.length() - i - 1));
continue;
}
int digit = Character.digit(c, radix);
if (digit >= 0) {
number += digit * pow(radix, (s.length() - i - 1));
} else {
throw new NumberFormatException("invalid character " + c + " code " +
(int) c);
}
throw new NumberFormatException("invalid character " + c + " code " +
(int) c);
}
if (negative) {

View File

@ -37,6 +37,10 @@ public class Vector<T> implements List<T> {
list.add(index, element);
}
public void insertElementAt(T element, int index) {
add(index, element);
}
public synchronized boolean add(T element) {
return list.add(element);
}
@ -57,6 +61,10 @@ public class Vector<T> implements List<T> {
return list.set(index, value);
}
public T setElementAt(T value, int index) {
return set(index, value);
}
public T elementAt(int index) {
return get(index);
}