add a few classes and methods to the classpath

Add java.lang.CharSequence, java.util.AbstractSet,
java.util.AbstractCollection, Collections.unmodifiableSet,
 System.getProperty(String,String), etc.
This commit is contained in:
Zsombor 2008-07-03 09:16:32 -06:00 committed by Joel Dice
parent 107ac01304
commit e3fd0d9c7d
10 changed files with 226 additions and 14 deletions

View File

@ -0,0 +1,11 @@
package java.lang;
public interface CharSequence {
public char charAt(int index);
int length();
CharSequence subSequence(int start, int end);
String toString();
}

View File

@ -415,4 +415,8 @@ public final class Class <T> {
return null;
}
}
public boolean desiredAssertionStatus() {
return false;
}
}

View File

@ -12,7 +12,7 @@ package java.lang;
import java.io.UnsupportedEncodingException;
public final class String implements Comparable<String> {
public final class String implements Comparable<String>, CharSequence {
private Object data;
private int offset;
private int length;
@ -425,6 +425,10 @@ public final class String implements Comparable<String> {
return array;
}
public CharSequence subSequence(int start, int end) {
return substring(start, end);
}
public native String intern();
public static String valueOf(Object s) {

View File

@ -10,7 +10,7 @@
package java.lang;
public class StringBuffer {
public class StringBuffer implements CharSequence {
private final StringBuilder sb;
public StringBuffer(String s) {
@ -116,4 +116,12 @@ public class StringBuffer {
public synchronized String toString() {
return sb.toString();
}
public String substring(int start, int end) {
return sb.substring(start, end);
}
public CharSequence subSequence(int start, int end) {
return sb.subSequence(start, end);
}
}

View File

@ -10,7 +10,7 @@
package java.lang;
public class StringBuilder {
public class StringBuilder implements CharSequence {
private static final int BufferSize = 32;
private Cell chain;
@ -288,4 +288,15 @@ public class StringBuilder {
this.next = next;
}
}
public String substring(int start, int end) {
int len = end-start;
char[] buf = new char[len];
getChars(start, len, buf,0 );
return new String(buf, 0, len, false);
}
public CharSequence subSequence(int start, int end) {
return substring(start, end);
}
}

View File

@ -53,6 +53,15 @@ public abstract class System {
return null;
}
public static String getProperty(String name, String defaultValue) {
String result = getProperty(name);
if (result==null) {
return defaultValue;
}
return result;
}
public static String setProperty(String name, String value) {
for (Property p = properties; p != null; p = p.next) {

View File

@ -0,0 +1,112 @@
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.util;
/**
* @author zsombor
*
*/
public abstract class AbstractCollection<T> implements Collection<T> {
/*
* (non-Javadoc)
*
* @see java.util.Collection#add(java.lang.Object)
*/
public boolean add(T element) {
throw new UnsupportedOperationException("adding to "
+ this.getClass().getName());
}
/*
* (non-Javadoc)
*
* @see java.util.Collection#addAll(java.util.Collection)
*/
public boolean addAll(Collection<? extends T> collection) {
boolean result = false;
for (T obj : collection) {
result |= add(obj);
}
return result;
}
/*
* (non-Javadoc)
*
* @see java.util.Collection#clear()
*/
public void clear() {
throw new UnsupportedOperationException("clear() in "
+ this.getClass().getName());
}
/*
* (non-Javadoc)
*
* @see java.util.Collection#contains(java.lang.Object)
*/
public boolean contains(T element) {
if (element != null) {
for (Iterator<T> iter = iterator(); iter.hasNext();) {
if (element.equals(iter.next())) {
return true;
}
}
} else {
for (Iterator<T> iter = iterator(); iter.hasNext();) {
if (iter.next()==null) {
return true;
}
}
}
return false;
}
/*
* (non-Javadoc)
*
* @see java.util.Collection#isEmpty()
*/
public boolean isEmpty() {
return size() == 0;
}
/*
* (non-Javadoc)
*
* @see java.util.Collection#remove(java.lang.Object)
*/
public boolean remove(T element) {
throw new UnsupportedOperationException("remove(T) in "
+ this.getClass().getName());
}
/*
* (non-Javadoc)
*
* @see java.util.Collection#size()
*/
public abstract int size();
/*
* (non-Javadoc)
*
* @see java.util.Collection#toArray(S[])
*/
public <S> S[] toArray(S[] array) {
return Collections.toArray(this, array);
}
public abstract Iterator<T> iterator();
}

View File

@ -0,0 +1,14 @@
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.util;
public abstract class AbstractSet<T> extends AbstractCollection<T> implements Set<T> {
}

View File

@ -187,4 +187,53 @@ public class Collections {
}
}
}
static class UnmodifiableSet<T> implements Set<T> {
Set<T> inner;
UnmodifiableSet(Set<T> inner) {
this.inner = inner;
}
public boolean add(T element) {
throw new UnsupportedOperationException("not supported");
}
public boolean addAll(Collection<? extends T> collection) {
throw new UnsupportedOperationException("not supported");
}
public void clear() {
throw new UnsupportedOperationException("not supported");
}
public boolean contains(T element) {
return inner.contains(element);
}
public boolean isEmpty() {
return inner.isEmpty();
}
public Iterator<T> iterator() {
return inner.iterator();
}
public boolean remove(T element) {
throw new UnsupportedOperationException("not supported");
}
public int size() {
return inner.size();
}
public <S> S[] toArray(S[] array) {
return inner.toArray(array);
}
}
public static <T> Set<T> unmodifiableSet(Set<T> hs) {
return new UnmodifiableSet<T>(hs);
}
}

View File

@ -10,7 +10,7 @@
package java.util;
public class TreeSet<T> implements Collection<T> {
public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
private PersistentSet<Cell<T>> set;
private int size;
@ -41,12 +41,6 @@ public class TreeSet<T> implements Collection<T> {
return false;
}
public boolean addAll(Collection<? extends T> collection) {
boolean change = false;
for (T t: collection) if (add(t)) change = true;
return change;
}
// Used by hashMaps for replacement
public void addAndReplace(T value) {
PersistentSet.Path<Cell<T>> p = set.find(new Cell(value, null));
@ -75,10 +69,6 @@ public class TreeSet<T> implements Collection<T> {
}
}
public <T> T[] toArray(T[] array) {
return Collections.toArray(this, array);
}
public int size() {
return size;
}