Skip to content

Commit

Permalink
Remove jdk6 dep
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Oct 13, 2009
1 parent db485fa commit 7360e4f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
Expand Up @@ -20,6 +20,7 @@

import org.jboss.weld.introspector.ConstructorSignature;
import org.jboss.weld.introspector.WeldConstructor;
import org.jboss.weld.util.collections.Arrays2;

public class ConstructorSignatureImpl implements ConstructorSignature
{
Expand Down Expand Up @@ -60,7 +61,7 @@ public int hashCode()

public String[] getParameterTypes()
{
return Arrays.copyOf(parameterTypes, parameterTypes.length);
return Arrays2.copyOf(parameterTypes, parameterTypes.length);
}

}
Expand Up @@ -21,6 +21,7 @@

import org.jboss.weld.introspector.MethodSignature;
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.util.collections.Arrays2;

public class MethodSignatureImpl implements MethodSignature
{
Expand Down Expand Up @@ -81,7 +82,7 @@ public String getMethodName()

public String[] getParameterTypes()
{
return Arrays.copyOf(parameterTypes, parameterTypes.length);
return Arrays2.copyOf(parameterTypes, parameterTypes.length);
}

@Override
Expand Down
55 changes: 55 additions & 0 deletions impl/src/main/java/org/jboss/weld/util/collections/Arrays2.java
Expand Up @@ -16,6 +16,7 @@
*/
package org.jboss.weld.util.collections;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -48,5 +49,59 @@ public static <T> Set<T> asSet(T... types)
}
return result;
}

// Cloning
/**
* Copies the specified array, truncating or padding with nulls (if necessary)
* so the copy has the specified length. For all indices that are
* valid in both the original array and the copy, the two arrays will
* contain identical values. For any indices that are valid in the
* copy but not the original, the copy will contain <tt>null</tt>.
* Such indices will exist if and only if the specified length
* is greater than that of the original array.
* The resulting array is of exactly the same class as the original array.
*
* @param original the array to be copied
* @param newLength the length of the copy to be returned
* @return a copy of the original array, truncated or padded with nulls
* to obtain the specified length
* @throws NegativeArraySizeException if <tt>newLength</tt> is negative
* @throws NullPointerException if <tt>original</tt> is null
* @since 1.6
*/
public static <T> T[] copyOf(T[] original, int newLength) {
return (T[]) copyOf(original, newLength, original.getClass());
}

/**
* Copies the specified array, truncating or padding with nulls (if necessary)
* so the copy has the specified length. For all indices that are
* valid in both the original array and the copy, the two arrays will
* contain identical values. For any indices that are valid in the
* copy but not the original, the copy will contain <tt>null</tt>.
* Such indices will exist if and only if the specified length
* is greater than that of the original array.
* The resulting array is of the class <tt>newType</tt>.
*
* @param original the array to be copied
* @param newLength the length of the copy to be returned
* @param newType the class of the copy to be returned
* @return a copy of the original array, truncated or padded with nulls
* to obtain the specified length
* @throws NegativeArraySizeException if <tt>newLength</tt> is negative
* @throws NullPointerException if <tt>original</tt> is null
* @throws ArrayStoreException if an element copied from
* <tt>original</tt> is not of a runtime type that can be stored in
* an array of class <tt>newType</tt>
* @since 1.6
*/
public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {
T[] copy = ((Object)newType == (Object)Object[].class)
? (T[]) new Object[newLength]
: (T[]) Array.newInstance(newType.getComponentType(), newLength);
System.arraycopy(original, 0, copy, 0,
Math.min(original.length, newLength));
return copy;
}

}
Expand Up @@ -20,6 +20,8 @@
import java.lang.reflect.Type;
import java.util.Arrays;

import org.jboss.weld.util.collections.Arrays2;

public class ParameterizedTypeImpl implements ParameterizedType
{
private final Type[] actualTypeArguments;
Expand All @@ -28,14 +30,14 @@ public class ParameterizedTypeImpl implements ParameterizedType

public ParameterizedTypeImpl(Type rawType, Type[] actualTypeArguments, Type ownerType)
{
this.actualTypeArguments = Arrays.copyOf(actualTypeArguments, actualTypeArguments.length);
this.actualTypeArguments = Arrays2.copyOf(actualTypeArguments, actualTypeArguments.length);
this.rawType = rawType;
this.ownerType = ownerType;
}

public Type[] getActualTypeArguments()
{
return Arrays.copyOf(actualTypeArguments, actualTypeArguments.length);
return Arrays2.copyOf(actualTypeArguments, actualTypeArguments.length);
}

public Type getOwnerType()
Expand Down

0 comments on commit 7360e4f

Please sign in to comment.