emul/src/main/java/java/lang/reflect/Array.java
branchArrayReflect
changeset 484 7ca6bd52b668
parent 483 7e39f344e4a0
child 485 d962d1330e54
     1.1 --- a/emul/src/main/java/java/lang/reflect/Array.java	Fri Jan 18 21:04:10 2013 +0100
     1.2 +++ b/emul/src/main/java/java/lang/reflect/Array.java	Fri Jan 18 21:21:35 2013 +0100
     1.3 @@ -439,8 +439,16 @@
     1.4       * the length of the specified array
     1.5       * @see Array#set
     1.6       */
     1.7 -    public static native void setByte(Object array, int index, byte b)
     1.8 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
     1.9 +    public static void setByte(Object array, int index, byte b)
    1.10 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.11 +        Class<?> t = array.getClass().getComponentType();
    1.12 +        if (t == Byte.TYPE) {
    1.13 +            byte[] arr = (byte[]) array;
    1.14 +            arr[index] = b;
    1.15 +        } else {
    1.16 +            setShort(array, index, b);
    1.17 +        }
    1.18 +    }
    1.19  
    1.20      /**
    1.21       * Sets the value of the indexed component of the specified array
    1.22 @@ -479,8 +487,17 @@
    1.23       * the length of the specified array
    1.24       * @see Array#set
    1.25       */
    1.26 -    public static native void setShort(Object array, int index, short s)
    1.27 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
    1.28 +    public static void setShort(Object array, int index, short s)
    1.29 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.30 +        Class<?> t = array.getClass().getComponentType();
    1.31 +        if (t == Short.TYPE) {
    1.32 +            short[] arr = (short[]) array;
    1.33 +            arr[index] = s;
    1.34 +        } else {
    1.35 +            setInt(array, index, s);
    1.36 +        }
    1.37 +        
    1.38 +    }
    1.39  
    1.40      /**
    1.41       * Sets the value of the indexed component of the specified array
    1.42 @@ -499,8 +516,16 @@
    1.43       * the length of the specified array
    1.44       * @see Array#set
    1.45       */
    1.46 -    public static native void setInt(Object array, int index, int i)
    1.47 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
    1.48 +    public static void setInt(Object array, int index, int i)
    1.49 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.50 +        Class<?> t = array.getClass().getComponentType();
    1.51 +        if (t == Integer.TYPE) {
    1.52 +            long[] arr = (long[]) array;
    1.53 +            arr[index] = i;
    1.54 +        } else {
    1.55 +            setLong(array, index, i);
    1.56 +        }
    1.57 +    }
    1.58  
    1.59      /**
    1.60       * Sets the value of the indexed component of the specified array
    1.61 @@ -519,8 +544,16 @@
    1.62       * the length of the specified array
    1.63       * @see Array#set
    1.64       */
    1.65 -    public static native void setLong(Object array, int index, long l)
    1.66 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
    1.67 +    public static void setLong(Object array, int index, long l)
    1.68 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.69 +        Class<?> t = array.getClass().getComponentType();
    1.70 +        if (t == Long.TYPE) {
    1.71 +            long[] arr = (long[]) array;
    1.72 +            arr[index] = l;
    1.73 +        } else {
    1.74 +            setFloat(array, index, l);
    1.75 +        }
    1.76 +    }
    1.77  
    1.78      /**
    1.79       * Sets the value of the indexed component of the specified array
    1.80 @@ -539,8 +572,16 @@
    1.81       * the length of the specified array
    1.82       * @see Array#set
    1.83       */
    1.84 -    public static native void setFloat(Object array, int index, float f)
    1.85 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
    1.86 +    public static void setFloat(Object array, int index, float f)
    1.87 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.88 +        Class<?> t = array.getClass().getComponentType();
    1.89 +        if (t == Float.TYPE) {
    1.90 +            float[] arr = (float[])array;
    1.91 +            arr[index] = f;
    1.92 +        } else {
    1.93 +            setDouble(array, index, f);
    1.94 +        }
    1.95 +    }
    1.96  
    1.97      /**
    1.98       * Sets the value of the indexed component of the specified array
    1.99 @@ -559,8 +600,16 @@
   1.100       * the length of the specified array
   1.101       * @see Array#set
   1.102       */
   1.103 -    public static native void setDouble(Object array, int index, double d)
   1.104 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
   1.105 +    public static void setDouble(Object array, int index, double d)
   1.106 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   1.107 +        Class<?> t = array.getClass().getComponentType();
   1.108 +        if (t == Double.TYPE) {
   1.109 +            double[] arr = (double[])array;
   1.110 +            arr[index] = d;
   1.111 +        } else {
   1.112 +            throw new IllegalArgumentException("argument type mismatch");
   1.113 +        }
   1.114 +    }
   1.115  
   1.116      /*
   1.117       * Private
   1.118 @@ -587,7 +636,4 @@
   1.119          }
   1.120          return arr;
   1.121      }
   1.122 -
   1.123 -
   1.124 -    
   1.125  }