mirror of
https://github.com/corda/corda.git
synced 2025-06-19 07:38:22 +00:00
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:
112
classpath/java/util/AbstractCollection.java
Normal file
112
classpath/java/util/AbstractCollection.java
Normal 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();
|
||||
|
||||
}
|
14
classpath/java/util/AbstractSet.java
Normal file
14
classpath/java/util/AbstractSet.java
Normal 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> {
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user