This adds the new 1.6 static methods to Collections
and Arrays, completing our collections framework
implementation to 1.6 level.

Changelog:

2006-12-28  Andrew John Hughes  <[EMAIL PROTECTED]>

        * java/util/Arrays.java:
        (copyOf(boolean[],int)): Implemented.
        (copyOfRange(boolean[],int,int)): Likewise.
        (copyOf(byte[],int)): Likewise.
        (copyOfRange(byte[],int,int)): Likewise.
        (copyOf(char[],int)): Likewise.
        (copyOfRange(char[],int,int)): Likewise.
        (copyOf(double[],int)): Likewise.
        (copyOfRange(double[],int,int)): Likewise.
        (copyOf(float[],int)): Likewise.
        (copyOfRange(float[],int,int)): Likewise.
        (copyOf(int[],int)): Likewise.
        (copyOfRange(int[],int,int)): Likewise.
        (copyOf(long[],int)): Likewise.
        (copyOfRange(long[],int,int)): Likewise.
        (copyOf(short[],int)): Likewise.
        (copyOfRange(short[],int,int)): Likewise.
        (copyOf(T[],int)): Likewise.
        (copyOfRange(T[],int,int)): Likewise.
        (copyOf(U[],int,Class<? extends T>)): Likewise.
        (copyOfRange(U[],int,int,Class<? extends T>)):
        Likewise.
        * java/util/Collections.java:
        (asLifoQueue(Deque<T>)): Implemented.
        (newSetFromMap(Map<E>)): Likewise.
        (MapSet): New class for newSetFromMap.
        (LIFOQueue): New class for asLifoQueue.

-- 
Andrew :-)

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: java/util/Arrays.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Arrays.java,v
retrieving revision 1.32
diff -u -3 -p -u -r1.32 Arrays.java
--- java/util/Arrays.java       25 Dec 2006 13:09:50 -0000      1.32
+++ java/util/Arrays.java       28 Dec 2006 23:23:18 -0000
@@ -3310,4 +3310,701 @@ public class Arrays
       return array;
     }
   }
+
+  /**
+   * Returns a copy of the supplied array, truncating or padding as
+   * necessary with <code>false</code> to obtain the specified length.
+   * Indices that are valid for both arrays will return the same value.
+   * Indices that only exist in the returned array (due to the new length
+   * being greater than the original length) will return <code>false</code>.
+   * This is equivalent to calling
+   * <code>copyOfRange(original, 0, newLength)</code>.
+   *
+   * @param original the original array to be copied.
+   * @param newLength the length of the returned array.
+   * @return a copy of the original array, truncated or padded with
+   *         <code>false</code> to obtain the required length.
+   * @throws NegativeArraySizeException if <code>newLength</code> is negative.
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOfRange(boolean[],int,int)
+   */
+  public static boolean[] copyOf(boolean[] original, int newLength)
+  {
+    if (newLength < 0)
+      throw new NegativeArraySizeException("The array size is negative.");
+    return copyOfRange(original, 0, newLength);
+  }
+
+  /**
+   * Copies the specified range of the supplied array to a new
+   * array, padding as necessary with <code>false</code>
+   * if <code>to</code> is greater than the length of the original
+   * array.  <code>from</code> must be in the range zero to
+   * <code>original.length</code> and can not be greater than
+   * <code>to</code>.  The initial element of the
+   * returned array will be equal to <code>original[from]</code>,
+   * except where <code>from</code> is equal to <code>to</code>
+   * (where a zero-length array will be returned) or <code>
+   * <code>from</code> is equal to <code>original.length</code>
+   * (where an array padded with <code>false</code> will be
+   * returned).  The returned array is always of length
+   * <code>to - from</code>.
+   *
+   * @param original the array from which to copy.
+   * @param from the initial index of the range, inclusive.
+   * @param to the final index of the range, exclusive.
+   * @return a copy of the specified range, with padding to
+   *         obtain the required length.
+   * @throws ArrayIndexOutOfBoundsException if <code>from < 0</code>
+   *                                        or <code>from > 
original.length</code>
+   * @throws IllegalArgumentException if <code>from > to</code>
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOf(boolean[],int)
+   */
+  public static boolean[] copyOfRange(boolean[] original, int from, int to)
+  {
+    if (from > to)
+      throw new IllegalArgumentException("The initial index is after " +
+                                        "the final index.");
+    boolean[] newArray = new boolean[to - from];
+    if (to > original.length)
+      {
+       System.arraycopy(original, from, newArray, 0,
+                        original.length - from);
+       fill(newArray, original.length, newArray.length, false);
+      }
+    else
+      System.arraycopy(original, from, newArray, 0, to - from);
+    return newArray;
+  }
+
+  /**
+   * Returns a copy of the supplied array, truncating or padding as
+   * necessary with <code>(byte)0</code> to obtain the specified length.
+   * Indices that are valid for both arrays will return the same value.
+   * Indices that only exist in the returned array (due to the new length
+   * being greater than the original length) will return <code>(byte)0</code>.
+   * This is equivalent to calling
+   * <code>copyOfRange(original, 0, newLength)</code>.
+   *
+   * @param original the original array to be copied.
+   * @param newLength the length of the returned array.
+   * @return a copy of the original array, truncated or padded with
+   *         <code>(byte)0</code> to obtain the required length.
+   * @throws NegativeArraySizeException if <code>newLength</code> is negative.
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOfRange(byte[],int,int)
+   */
+  public static byte[] copyOf(byte[] original, int newLength)
+  {
+    if (newLength < 0)
+      throw new NegativeArraySizeException("The array size is negative.");
+    return copyOfRange(original, 0, newLength);
+  }
+
+  /**
+   * Copies the specified range of the supplied array to a new
+   * array, padding as necessary with <code>(byte)0</code>
+   * if <code>to</code> is greater than the length of the original
+   * array.  <code>from</code> must be in the range zero to
+   * <code>original.length</code> and can not be greater than
+   * <code>to</code>.  The initial element of the
+   * returned array will be equal to <code>original[from]</code>,
+   * except where <code>from</code> is equal to <code>to</code>
+   * (where a zero-length array will be returned) or <code>
+   * <code>from</code> is equal to <code>original.length</code>
+   * (where an array padded with <code>(byte)0</code> will be
+   * returned).  The returned array is always of length
+   * <code>to - from</code>.
+   *
+   * @param original the array from which to copy.
+   * @param from the initial index of the range, inclusive.
+   * @param to the final index of the range, exclusive.
+   * @return a copy of the specified range, with padding to
+   *         obtain the required length.
+   * @throws ArrayIndexOutOfBoundsException if <code>from < 0</code>
+   *                                        or <code>from > 
original.length</code>
+   * @throws IllegalArgumentException if <code>from > to</code>
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOf(byte[],int)
+   */
+  public static byte[] copyOfRange(byte[] original, int from, int to)
+  {
+    if (from > to)
+      throw new IllegalArgumentException("The initial index is after " +
+                                        "the final index.");
+    byte[] newArray = new byte[to - from];
+    if (to > original.length)
+      {
+       System.arraycopy(original, from, newArray, 0,
+                        original.length - from);
+       fill(newArray, original.length, newArray.length, (byte)0);
+      }
+    else
+      System.arraycopy(original, from, newArray, 0, to - from);
+    return newArray;
+  }
+
+  /**
+   * Returns a copy of the supplied array, truncating or padding as
+   * necessary with <code>'\0'</code> to obtain the specified length.
+   * Indices that are valid for both arrays will return the same value.
+   * Indices that only exist in the returned array (due to the new length
+   * being greater than the original length) will return <code>'\0'</code>.
+   * This is equivalent to calling
+   * <code>copyOfRange(original, 0, newLength)</code>.
+   *
+   * @param original the original array to be copied.
+   * @param newLength the length of the returned array.
+   * @return a copy of the original array, truncated or padded with
+   *         <code>'\0'</code> to obtain the required length.
+   * @throws NegativeArraySizeException if <code>newLength</code> is negative.
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOfRange(char[],int,int)
+   */
+  public static char[] copyOf(char[] original, int newLength)
+  {
+    if (newLength < 0)
+      throw new NegativeArraySizeException("The array size is negative.");
+    return copyOfRange(original, 0, newLength);
+  }
+
+  /**
+   * Copies the specified range of the supplied array to a new
+   * array, padding as necessary with <code>'\0'</code>
+   * if <code>to</code> is greater than the length of the original
+   * array.  <code>from</code> must be in the range zero to
+   * <code>original.length</code> and can not be greater than
+   * <code>to</code>.  The initial element of the
+   * returned array will be equal to <code>original[from]</code>,
+   * except where <code>from</code> is equal to <code>to</code>
+   * (where a zero-length array will be returned) or <code>
+   * <code>from</code> is equal to <code>original.length</code>
+   * (where an array padded with <code>'\0'</code> will be
+   * returned).  The returned array is always of length
+   * <code>to - from</code>.
+   *
+   * @param original the array from which to copy.
+   * @param from the initial index of the range, inclusive.
+   * @param to the final index of the range, exclusive.
+   * @return a copy of the specified range, with padding to
+   *         obtain the required length.
+   * @throws ArrayIndexOutOfBoundsException if <code>from < 0</code>
+   *                                        or <code>from > 
original.length</code>
+   * @throws IllegalArgumentException if <code>from > to</code>
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOf(char[],int)
+   */
+  public static char[] copyOfRange(char[] original, int from, int to)
+  {
+    if (from > to)
+      throw new IllegalArgumentException("The initial index is after " +
+                                        "the final index.");
+    char[] newArray = new char[to - from];
+    if (to > original.length)
+      {
+       System.arraycopy(original, from, newArray, 0,
+                        original.length - from);
+       fill(newArray, original.length, newArray.length, '\0');
+      }
+    else
+      System.arraycopy(original, from, newArray, 0, to - from);
+    return newArray;
+  }
+
+  /**
+   * Returns a copy of the supplied array, truncating or padding as
+   * necessary with <code>0d</code> to obtain the specified length.
+   * Indices that are valid for both arrays will return the same value.
+   * Indices that only exist in the returned array (due to the new length
+   * being greater than the original length) will return <code>0d</code>.
+   * This is equivalent to calling
+   * <code>copyOfRange(original, 0, newLength)</code>.
+   *
+   * @param original the original array to be copied.
+   * @param newLength the length of the returned array.
+   * @return a copy of the original array, truncated or padded with
+   *         <code>0d</code> to obtain the required length.
+   * @throws NegativeArraySizeException if <code>newLength</code> is negative.
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOfRange(double[],int,int)
+   */
+  public static double[] copyOf(double[] original, int newLength)
+  {
+    if (newLength < 0)
+      throw new NegativeArraySizeException("The array size is negative.");
+    return copyOfRange(original, 0, newLength);
+  }
+
+  /**
+   * Copies the specified range of the supplied array to a new
+   * array, padding as necessary with <code>0d</code>
+   * if <code>to</code> is greater than the length of the original
+   * array.  <code>from</code> must be in the range zero to
+   * <code>original.length</code> and can not be greater than
+   * <code>to</code>.  The initial element of the
+   * returned array will be equal to <code>original[from]</code>,
+   * except where <code>from</code> is equal to <code>to</code>
+   * (where a zero-length array will be returned) or <code>
+   * <code>from</code> is equal to <code>original.length</code>
+   * (where an array padded with <code>0d</code> will be
+   * returned).  The returned array is always of length
+   * <code>to - from</code>.
+   *
+   * @param original the array from which to copy.
+   * @param from the initial index of the range, inclusive.
+   * @param to the final index of the range, exclusive.
+   * @return a copy of the specified range, with padding to
+   *         obtain the required length.
+   * @throws ArrayIndexOutOfBoundsException if <code>from < 0</code>
+   *                                        or <code>from > 
original.length</code>
+   * @throws IllegalArgumentException if <code>from > to</code>
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOf(double[],int)
+   */
+  public static double[] copyOfRange(double[] original, int from, int to)
+  {
+    if (from > to)
+      throw new IllegalArgumentException("The initial index is after " +
+                                        "the final index.");
+    double[] newArray = new double[to - from];
+    if (to > original.length)
+      {
+       System.arraycopy(original, from, newArray, 0,
+                        original.length - from);
+       fill(newArray, original.length, newArray.length, 0d);
+      }
+    else
+      System.arraycopy(original, from, newArray, 0, to - from);
+    return newArray;
+  }
+
+  /**
+   * Returns a copy of the supplied array, truncating or padding as
+   * necessary with <code>0f</code> to obtain the specified length.
+   * Indices that are valid for both arrays will return the same value.
+   * Indices that only exist in the returned array (due to the new length
+   * being greater than the original length) will return <code>0f</code>.
+   * This is equivalent to calling
+   * <code>copyOfRange(original, 0, newLength)</code>.
+   *
+   * @param original the original array to be copied.
+   * @param newLength the length of the returned array.
+   * @return a copy of the original array, truncated or padded with
+   *         <code>0f</code> to obtain the required length.
+   * @throws NegativeArraySizeException if <code>newLength</code> is negative.
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOfRange(float[],int,int)
+   */
+  public static float[] copyOf(float[] original, int newLength)
+  {
+    if (newLength < 0)
+      throw new NegativeArraySizeException("The array size is negative.");
+    return copyOfRange(original, 0, newLength);
+  }
+
+  /**
+   * Copies the specified range of the supplied array to a new
+   * array, padding as necessary with <code>0f</code>
+   * if <code>to</code> is greater than the length of the original
+   * array.  <code>from</code> must be in the range zero to
+   * <code>original.length</code> and can not be greater than
+   * <code>to</code>.  The initial element of the
+   * returned array will be equal to <code>original[from]</code>,
+   * except where <code>from</code> is equal to <code>to</code>
+   * (where a zero-length array will be returned) or <code>
+   * <code>from</code> is equal to <code>original.length</code>
+   * (where an array padded with <code>0f</code> will be
+   * returned).  The returned array is always of length
+   * <code>to - from</code>.
+   *
+   * @param original the array from which to copy.
+   * @param from the initial index of the range, inclusive.
+   * @param to the final index of the range, exclusive.
+   * @return a copy of the specified range, with padding to
+   *         obtain the required length.
+   * @throws ArrayIndexOutOfBoundsException if <code>from < 0</code>
+   *                                        or <code>from > 
original.length</code>
+   * @throws IllegalArgumentException if <code>from > to</code>
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOf(float[],int)
+   */
+  public static float[] copyOfRange(float[] original, int from, int to)
+  {
+    if (from > to)
+      throw new IllegalArgumentException("The initial index is after " +
+                                        "the final index.");
+    float[] newArray = new float[to - from];
+    if (to > original.length)
+      {
+       System.arraycopy(original, from, newArray, 0,
+                        original.length - from);
+       fill(newArray, original.length, newArray.length, 0f);
+      }
+    else
+      System.arraycopy(original, from, newArray, 0, to - from);
+    return newArray;
+  }
+
+  /**
+   * Returns a copy of the supplied array, truncating or padding as
+   * necessary with <code>0</code> to obtain the specified length.
+   * Indices that are valid for both arrays will return the same value.
+   * Indices that only exist in the returned array (due to the new length
+   * being greater than the original length) will return <code>0</code>.
+   * This is equivalent to calling
+   * <code>copyOfRange(original, 0, newLength)</code>.
+   *
+   * @param original the original array to be copied.
+   * @param newLength the length of the returned array.
+   * @return a copy of the original array, truncated or padded with
+   *         <code>0</code> to obtain the required length.
+   * @throws NegativeArraySizeException if <code>newLength</code> is negative.
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOfRange(int[],int,int)
+   */
+  public static int[] copyOf(int[] original, int newLength)
+  {
+    if (newLength < 0)
+      throw new NegativeArraySizeException("The array size is negative.");
+    return copyOfRange(original, 0, newLength);
+  }
+
+  /**
+   * Copies the specified range of the supplied array to a new
+   * array, padding as necessary with <code>0</code>
+   * if <code>to</code> is greater than the length of the original
+   * array.  <code>from</code> must be in the range zero to
+   * <code>original.length</code> and can not be greater than
+   * <code>to</code>.  The initial element of the
+   * returned array will be equal to <code>original[from]</code>,
+   * except where <code>from</code> is equal to <code>to</code>
+   * (where a zero-length array will be returned) or <code>
+   * <code>from</code> is equal to <code>original.length</code>
+   * (where an array padded with <code>0</code> will be
+   * returned).  The returned array is always of length
+   * <code>to - from</code>.
+   *
+   * @param original the array from which to copy.
+   * @param from the initial index of the range, inclusive.
+   * @param to the final index of the range, exclusive.
+   * @return a copy of the specified range, with padding to
+   *         obtain the required length.
+   * @throws ArrayIndexOutOfBoundsException if <code>from < 0</code>
+   *                                        or <code>from > 
original.length</code>
+   * @throws IllegalArgumentException if <code>from > to</code>
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOf(int[],int)
+   */
+  public static int[] copyOfRange(int[] original, int from, int to)
+  {
+    if (from > to)
+      throw new IllegalArgumentException("The initial index is after " +
+                                        "the final index.");
+    int[] newArray = new int[to - from];
+    if (to > original.length)
+      {
+       System.arraycopy(original, from, newArray, 0,
+                        original.length - from);
+       fill(newArray, original.length, newArray.length, 0);
+      }
+    else
+      System.arraycopy(original, from, newArray, 0, to - from);
+    return newArray;
+  }
+
+  /**
+   * Returns a copy of the supplied array, truncating or padding as
+   * necessary with <code>0L</code> to obtain the specified length.
+   * Indices that are valid for both arrays will return the same value.
+   * Indices that only exist in the returned array (due to the new length
+   * being greater than the original length) will return <code>0L</code>.
+   * This is equivalent to calling
+   * <code>copyOfRange(original, 0, newLength)</code>.
+   *
+   * @param original the original array to be copied.
+   * @param newLength the length of the returned array.
+   * @return a copy of the original array, truncated or padded with
+   *         <code>0L</code> to obtain the required length.
+   * @throws NegativeArraySizeException if <code>newLength</code> is negative.
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOfRange(long[],int,int)
+   */
+  public static long[] copyOf(long[] original, int newLength)
+  {
+    if (newLength < 0)
+      throw new NegativeArraySizeException("The array size is negative.");
+    return copyOfRange(original, 0, newLength);
+  }
+
+  /**
+   * Copies the specified range of the supplied array to a new
+   * array, padding as necessary with <code>0L</code>
+   * if <code>to</code> is greater than the length of the original
+   * array.  <code>from</code> must be in the range zero to
+   * <code>original.length</code> and can not be greater than
+   * <code>to</code>.  The initial element of the
+   * returned array will be equal to <code>original[from]</code>,
+   * except where <code>from</code> is equal to <code>to</code>
+   * (where a zero-length array will be returned) or <code>
+   * <code>from</code> is equal to <code>original.length</code>
+   * (where an array padded with <code>0L</code> will be
+   * returned).  The returned array is always of length
+   * <code>to - from</code>.
+   *
+   * @param original the array from which to copy.
+   * @param from the initial index of the range, inclusive.
+   * @param to the final index of the range, exclusive.
+   * @return a copy of the specified range, with padding to
+   *         obtain the required length.
+   * @throws ArrayIndexOutOfBoundsException if <code>from < 0</code>
+   *                                        or <code>from > 
original.length</code>
+   * @throws IllegalArgumentException if <code>from > to</code>
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOf(long[],int)
+   */
+  public static long[] copyOfRange(long[] original, int from, int to)
+  {
+    if (from > to)
+      throw new IllegalArgumentException("The initial index is after " +
+                                        "the final index.");
+    long[] newArray = new long[to - from];
+    if (to > original.length)
+      {
+       System.arraycopy(original, from, newArray, 0,
+                        original.length - from);
+       fill(newArray, original.length, newArray.length, 0L);
+      }
+    else
+      System.arraycopy(original, from, newArray, 0, to - from);
+    return newArray;
+  }
+
+  /**
+   * Returns a copy of the supplied array, truncating or padding as
+   * necessary with <code>(short)0</code> to obtain the specified length.
+   * Indices that are valid for both arrays will return the same value.
+   * Indices that only exist in the returned array (due to the new length
+   * being greater than the original length) will return <code>(short)0</code>.
+   * This is equivalent to calling
+   * <code>copyOfRange(original, 0, newLength)</code>.
+   *
+   * @param original the original array to be copied.
+   * @param newLength the length of the returned array.
+   * @return a copy of the original array, truncated or padded with
+   *         <code>(short)0</code> to obtain the required length.
+   * @throws NegativeArraySizeException if <code>newLength</code> is negative.
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOfRange(short[],int,int)
+   */
+  public static short[] copyOf(short[] original, int newLength)
+  {
+    if (newLength < 0)
+      throw new NegativeArraySizeException("The array size is negative.");
+    return copyOfRange(original, 0, newLength);
+  }
+
+  /**
+   * Copies the specified range of the supplied array to a new
+   * array, padding as necessary with <code>(short)0</code>
+   * if <code>to</code> is greater than the length of the original
+   * array.  <code>from</code> must be in the range zero to
+   * <code>original.length</code> and can not be greater than
+   * <code>to</code>.  The initial element of the
+   * returned array will be equal to <code>original[from]</code>,
+   * except where <code>from</code> is equal to <code>to</code>
+   * (where a zero-length array will be returned) or <code>
+   * <code>from</code> is equal to <code>original.length</code>
+   * (where an array padded with <code>(short)0</code> will be
+   * returned).  The returned array is always of length
+   * <code>to - from</code>.
+   *
+   * @param original the array from which to copy.
+   * @param from the initial index of the range, inclusive.
+   * @param to the final index of the range, exclusive.
+   * @return a copy of the specified range, with padding to
+   *         obtain the required length.
+   * @throws ArrayIndexOutOfBoundsException if <code>from < 0</code>
+   *                                        or <code>from > 
original.length</code>
+   * @throws IllegalArgumentException if <code>from > to</code>
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOf(short[],int)
+   */
+  public static short[] copyOfRange(short[] original, int from, int to)
+  {
+    if (from > to)
+      throw new IllegalArgumentException("The initial index is after " +
+                                        "the final index.");
+    short[] newArray = new short[to - from];
+    if (to > original.length)
+      {
+       System.arraycopy(original, from, newArray, 0,
+                        original.length - from);
+       fill(newArray, original.length, newArray.length, (short)0);
+      }
+    else
+      System.arraycopy(original, from, newArray, 0, to - from);
+    return newArray;
+  }
+
+  /**
+   * Returns a copy of the supplied array, truncating or padding as
+   * necessary with <code>null</code> to obtain the specified length.
+   * Indices that are valid for both arrays will return the same value.
+   * Indices that only exist in the returned array (due to the new length
+   * being greater than the original length) will return <code>null</code>.
+   * This is equivalent to calling
+   * <code>copyOfRange(original, 0, newLength)</code>.
+   *
+   * @param original the original array to be copied.
+   * @param newLength the length of the returned array.
+   * @return a copy of the original array, truncated or padded with
+   *         <code>null</code> to obtain the required length.
+   * @throws NegativeArraySizeException if <code>newLength</code> is negative.
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOfRange(T[],int,int)
+   */
+  public static <T> T[] copyOf(T[] original, int newLength)
+  {
+    if (newLength < 0)
+      throw new NegativeArraySizeException("The array size is negative.");
+    return copyOfRange(original, 0, newLength);
+  }
+
+  /**
+   * Copies the specified range of the supplied array to a new
+   * array, padding as necessary with <code>null</code>
+   * if <code>to</code> is greater than the length of the original
+   * array.  <code>from</code> must be in the range zero to
+   * <code>original.length</code> and can not be greater than
+   * <code>to</code>.  The initial element of the
+   * returned array will be equal to <code>original[from]</code>,
+   * except where <code>from</code> is equal to <code>to</code>
+   * (where a zero-length array will be returned) or <code>
+   * <code>from</code> is equal to <code>original.length</code>
+   * (where an array padded with <code>null</code> will be
+   * returned).  The returned array is always of length
+   * <code>to - from</code>.
+   *
+   * @param original the array from which to copy.
+   * @param from the initial index of the range, inclusive.
+   * @param to the final index of the range, exclusive.
+   * @return a copy of the specified range, with padding to
+   *         obtain the required length.
+   * @throws ArrayIndexOutOfBoundsException if <code>from < 0</code>
+   *                                        or <code>from > 
original.length</code>
+   * @throws IllegalArgumentException if <code>from > to</code>
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOf(T[],int)
+   */
+  public static <T> T[] copyOfRange(T[] original, int from, int to)
+  {
+    if (from > to)
+      throw new IllegalArgumentException("The initial index is after " +
+                                        "the final index.");
+    T[] newArray = (T[]) new Object[to - from];
+    if (to > original.length)
+      {
+       System.arraycopy(original, from, newArray, 0,
+                        original.length - from);
+       fill(newArray, original.length, newArray.length, null);
+      }
+    else
+      System.arraycopy(original, from, newArray, 0, to - from);
+    return newArray;
+  }
+
+  /**
+   * Returns a copy of the supplied array, truncating or padding as
+   * necessary with <code>null</code> to obtain the specified length.
+   * Indices that are valid for both arrays will return the same value.
+   * Indices that only exist in the returned array (due to the new length
+   * being greater than the original length) will return <code>null</code>.
+   * This is equivalent to calling
+   * <code>copyOfRange(original, 0, newLength, newType)</code>.  The returned
+   * array will be of the specified type, <code>newType</code>.
+   *
+   * @param original the original array to be copied.
+   * @param newLength the length of the returned array.
+   * @param newType the type of the returned array.
+   * @return a copy of the original array, truncated or padded with
+   *         <code>null</code> to obtain the required length.
+   * @throws NegativeArraySizeException if <code>newLength</code> is negative.
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOfRange(U[],int,int,Class)
+   */
+  public static <T,U> T[] copyOf(U[] original, int newLength,
+                                Class<? extends T[]> newType)
+  {
+    if (newLength < 0)
+      throw new NegativeArraySizeException("The array size is negative.");
+    return copyOfRange(original, 0, newLength, newType);
+  }
+
+  /**
+   * Copies the specified range of the supplied array to a new
+   * array, padding as necessary with <code>null</code>
+   * if <code>to</code> is greater than the length of the original
+   * array.  <code>from</code> must be in the range zero to
+   * <code>original.length</code> and can not be greater than
+   * <code>to</code>.  The initial element of the
+   * returned array will be equal to <code>original[from]</code>,
+   * except where <code>from</code> is equal to <code>to</code>
+   * (where a zero-length array will be returned) or <code>
+   * <code>from</code> is equal to <code>original.length</code>
+   * (where an array padded with <code>null</code> will be
+   * returned).  The returned array is always of length
+   * <code>to - from</code> and will be of the specified type,
+   * <code>newType</code>.
+   *
+   * @param original the array from which to copy.
+   * @param from the initial index of the range, inclusive.
+   * @param to the final index of the range, exclusive.
+   * @param newType the type of the returned array.
+   * @return a copy of the specified range, with padding to
+   *         obtain the required length.
+   * @throws ArrayIndexOutOfBoundsException if <code>from < 0</code>
+   *                                        or <code>from > 
original.length</code>
+   * @throws IllegalArgumentException if <code>from > to</code>
+   * @throws NullPointerException if <code>original</code> is 
<code>null</code>.
+   * @since 1.6
+   * @see #copyOf(T[],int)
+   */
+  public static <T,U> T[] copyOfRange(U[] original, int from, int to,
+                                     Class<? extends T[]> newType)
+  {
+    if (from > to)
+      throw new IllegalArgumentException("The initial index is after " +
+                                        "the final index.");
+    T[] newArray = (T[]) Array.newInstance(newType.getComponentType(),
+                                          to - from);
+    if (to > original.length)
+      {
+       System.arraycopy(original, from, newArray, 0,
+                        original.length - from);
+       fill(newArray, original.length, newArray.length, null);
+      }
+    else
+      System.arraycopy(original, from, newArray, 0, to - from);
+    return newArray;
+  }
 }
Index: java/util/Collections.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Collections.java,v
retrieving revision 1.48
diff -u -3 -p -u -r1.48 Collections.java
--- java/util/Collections.java  21 Dec 2006 13:02:50 -0000      1.48
+++ java/util/Collections.java  28 Dec 2006 23:23:19 -0000
@@ -7425,4 +7425,187 @@ public class Collections
     }
   } // class CheckedSortedSet
 
+  /**
+   * Returns a view of a [EMAIL PROTECTED] Deque} as a stack or LIFO 
(Last-In-First-Out)
+   * [EMAIL PROTECTED] Queue}.  Each call to the LIFO queue corresponds to one
+   * equivalent method call to the underlying deque, with the exception
+   * of [EMAIL PROTECTED] Collection#addAll(Collection)}, which is emulated by 
a series
+   * of [EMAIL PROTECTED] Deque#push(E)} calls.
+   *
+   * @param deque the deque to convert to a LIFO queue.
+   * @return a LIFO queue.
+   * @since 1.6
+   */
+  public static <T> Queue<T> asLifoQueue(Deque<T> deque)
+  {
+    return new LIFOQueue<T>(deque);
+  }
+
+  /**
+   * Returns a set backed by the supplied map.  The resulting set
+   * has the same performance, concurrency and ordering characteristics
+   * as the original map.  The supplied map must be empty and should not
+   * be used after the set is created.  Each call to the set corresponds
+   * to one equivalent method call to the underlying map, with the exception
+   * of [EMAIL PROTECTED] Set#addAll(Collection)} which is emulated by a 
series of
+   * calls to <code>put</code>.
+   *
+   * @param map the map to convert to a set.
+   * @return a set backed by the supplied map.
+   * @throws IllegalArgumentException if the map is not empty.
+   * @since 1.6
+   */
+  public static <E> Set<E> newSetFromMap(Map<E,Boolean> map)
+  {
+    return new MapSet<E>(map);
+  }
+
+  /**
+   * The implementation of [EMAIL PROTECTED] #asLIFOQueue(Deque)}. 
+   *
+   * @author Andrew John Hughes ([EMAIL PROTECTED])
+   * @since 1.6
+   */
+  private static class LIFOQueue<T>
+    extends AbstractQueue<T>
+  {
+    
+    /**
+     * The backing deque.
+     */
+    private Deque<T> deque;
+
+    /**
+     * Constructs a new [EMAIL PROTECTED] LIFOQueue} with the specified
+     * backing [EMAIL PROTECTED] Deque}.
+     *
+     * @param deque the backing deque.
+     */
+    public LIFOQueue(Deque<T> deque)
+    {
+      this.deque = deque;
+    }
+
+    public boolean add(T e)
+    {
+      return deque.offerFirst(e);
+    }
+    
+    public boolean addAll(Collection<? extends T> c)
+    {
+      boolean result = false;
+      for (T e : c)
+       result |= deque.offerFirst(e);
+      return result;
+    }
+    
+    public void clear()
+    {
+      deque.clear();
+    }
+    
+    public boolean isEmpty()
+    {
+      return deque.isEmpty();
+    }
+    
+    public Iterator<T> iterator()
+    {
+      return deque.iterator();
+    }
+    
+    public boolean offer(T e)
+    {
+      return deque.offerFirst(e);
+    }
+    
+    public T peek()
+    {
+      return deque.peek();
+    }
+
+    public T poll()
+    {
+      return deque.poll();
+    }
+    
+    public int size()
+    {
+      return deque.size();
+    }
+  } // class LIFOQueue
+
+  /**
+   * The implementation of [EMAIL PROTECTED] #newSetFromMap(Map)}. 
+   *
+   * @author Andrew John Hughes ([EMAIL PROTECTED])
+   * @since 1.6
+   */
+  private static class MapSet<E>
+    extends AbstractSet<E>
+  {
+    
+    /**
+     * The backing map.
+     */
+    private Map<E,Boolean> map;
+
+    /**
+     * Constructs a new [EMAIL PROTECTED] MapSet} using the specified
+     * backing [EMAIL PROTECTED] Map}.
+     *
+     * @param map the backing map.
+     * @throws IllegalArgumentException if the map is not empty.
+     */
+    public MapSet(Map<E,Boolean> map)
+    {
+      if (!map.isEmpty())
+       throw new IllegalArgumentException("The map must be empty.");
+      this.map = map;
+    }
+
+    public boolean add(E e)
+    {
+      return map.put(e, true) == null;
+    }
+    
+    public boolean addAll(Collection<? extends E> c)
+    {
+      boolean result = false;
+      for (E e : c)
+       result |= (map.put(e, true) == null);
+      return result;
+    }
+    
+    public void clear()
+    {
+      map.clear();
+    }
+    
+    public boolean contains(Object o)
+    {
+      return map.containsKey(o);
+    }
+    
+    public boolean isEmpty()
+    {
+      return map.isEmpty();
+    }
+    
+    public Iterator<E> iterator()
+    {
+      return map.keySet().iterator();
+    }
+    
+    public boolean remove(Object o)
+    {
+      return map.remove(o) != null;
+    }
+    
+    public int size()
+    {
+      return map.size();
+    }
+  } // class MapSet
+  
 } // class Collections

Attachment: signature.asc
Description: Digital signature

Reply via email to