[Nice-commit] Nice/stdlib/nice/lang rawArray.java,1.14,1.15
Brought to you by:
bonniot
From: Arjan B. <ar...@us...> - 2004-06-27 16:10:36
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19009/F:/nice/stdlib/nice/lang Modified Files: rawArray.java Log Message: More flexible variant of reflect.Array.set() (not used yet) Index: rawArray.java =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/rawArray.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** rawArray.java 11 Feb 2004 12:46:39 -0000 1.14 --- rawArray.java 27 Jun 2004 16:10:24 -0000 1.15 *************** *** 409,411 **** --- 409,444 ---- } } + + /**************************************************************** + * Utility functions + ****************************************************************/ + + /** + Variant of java.lang.reflect.Array.set that is more flexible about how + the primitive values are boxed. + */ + public static void Array_set(Object array, int index, Object value) + { + if (array instanceof Object[]) + ((Object[])array)[index] = value; + else if (array instanceof int[]) + ((int[])array)[index] = ((Number)value).intValue(); + else if (array instanceof byte[]) + ((byte[])array)[index] = ((Number)value).byteValue(); + else if (array instanceof long[]) + ((long[])array)[index] = ((Number)value).longValue(); + else if (array instanceof char[]) + ((char[])array)[index] = ((Character)value).charValue(); + else if (array instanceof boolean[]) + ((boolean[])array)[index] = ((Boolean)value).booleanValue(); + else if (array instanceof double[]) + ((double[])array)[index] = ((Number)value).doubleValue(); + else if (array instanceof float[]) + ((float[])array)[index] = ((Number)value).floatValue(); + else if (array instanceof short[]) + ((short[])array)[index] = ((Number)value).shortValue(); + else + throw new IllegalArgumentException(); + } + } |