corda/classpath/java/util/Arrays.java

71 lines
1.5 KiB
Java
Raw Normal View History

2007-07-22 03:47:29 +00:00
package java.util;
public class Arrays {
private Arrays() { }
2007-08-24 01:57:42 +00:00
public static String toString(Object[] a) {
return asList(a).toString();
}
2007-07-22 19:06:21 +00:00
private static boolean equal(Object a, Object b) {
return (a == null && b == null) || (a != null && a.equals(b));
}
2007-07-22 03:47:29 +00:00
public static <T> List<T> asList(final T ... array) {
return new List<T>() {
2007-08-24 01:57:42 +00:00
public String toString() {
return Collections.toString(this);
}
2007-07-22 03:47:29 +00:00
public int size() {
return array.length;
}
public boolean add(T element) {
throw new UnsupportedOperationException();
}
public void add(int index, T element) {
throw new UnsupportedOperationException();
}
2007-07-22 19:06:21 +00:00
public boolean contains(T element) {
for (int i = 0; i < array.length; ++i) {
if (equal(element, array[i])) {
return true;
}
}
return false;
}
2007-07-22 03:47:29 +00:00
public T get(int index) {
return array[index];
}
public <S> S[] toArray(S[] a) {
return (S[])array;
}
public boolean isEmpty() {
return size() == 0;
}
2007-07-22 03:47:29 +00:00
public T remove(int index) {
throw new UnsupportedOperationException();
}
public boolean remove(T element) {
throw new UnsupportedOperationException();
}
public void clear() {
throw new UnsupportedOperationException();
}
public Iterator<T> iterator() {
return new Collections.ArrayListIterator(this);
}
};
}
}