diff --git a/classpath/java/util/Arrays.java b/classpath/java/util/Arrays.java index b978b5c5ff..15b6ec20ae 100644 --- a/classpath/java/util/Arrays.java +++ b/classpath/java/util/Arrays.java @@ -144,6 +144,7 @@ public class Arrays { public static void sort(Object[] array) { sort(array, new Comparator() { + @Override public int compare(Object a, Object b) { return ((Comparable) a).compareTo(b); } @@ -306,14 +307,17 @@ public class Arrays { public static List asList(final T ... array) { return new AbstractList() { + @Override public int size() { return array.length; } + @Override public void add(int index, T element) { throw new UnsupportedOperationException(); } - + + @Override public int indexOf(Object element) { for (int i = 0; i < array.length; ++i) { if (equal(element, array[i])) { @@ -323,6 +327,7 @@ public class Arrays { return -1; } + @Override public int lastIndexOf(Object element) { for (int i = array.length - 1; i >= 0; --i) { if (equal(element, array[i])) { @@ -331,19 +336,23 @@ public class Arrays { } return -1; } - + + @Override public T get(int index) { return array[index]; } + @Override public T set(int index, T value) { throw new UnsupportedOperationException(); } + @Override public T remove(int index) { throw new UnsupportedOperationException(); } + @Override public ListIterator listIterator(int index) { return new Collections.ArrayListIterator(this, index); } diff --git a/classpath/java/util/Objects.java b/classpath/java/util/Objects.java new file mode 100644 index 0000000000..586ee916bb --- /dev/null +++ b/classpath/java/util/Objects.java @@ -0,0 +1,64 @@ +package java.util; + +public final class Objects { + private Objects() { + throw new AssertionError("Instantiating java.long.Objetcs is not allowed!"); + } + + public static int compare(final T x, final T y, final Comparator comparator) { + if (x == y) + return 0; + else + return comparator.compare(x, y); + } + + public static boolean deepEquals(final Object x, final Object y) { + if (x == y) + return true; + if (x == null || y == null) + return false; + throw new UnsupportedOperationException("deepEquals is not implemented yet."); + } + + public static boolean equals(final Object x, final Object y) { + if (x == y) + return true; + if (x != null) + return x.equals(y); + return false; + } + + public static int hash(final Object... values) { + return Arrays.hashCode(values); + } + + public static int hashCode(final Object value) { + if (value == null) + return 0; + return value.hashCode(); + } + + public static T requireNonNull(final T value) { + if (value == null) + throw new NullPointerException(); + else + return value; + } + + public static T requireNonNull(final T value, String message) { + if (value == null) + throw new NullPointerException(message); + else + return value; + } + + public static String toString(final Object value) { + return String.valueOf(value); + } + + public static String toString(final Object value, final String defaultValue) { + if (value == null) + return defaultValue; + return value.toString(); + } +}