1 | // FileDescriptor.java - Open file or device
|
---|
2 |
|
---|
3 | /* Copyright (C) 1999 Free Software Foundation
|
---|
4 |
|
---|
5 | This file is part of libgcj.
|
---|
6 |
|
---|
7 | This software is copyrighted work licensed under the terms of the
|
---|
8 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
---|
9 | details. */
|
---|
10 |
|
---|
11 | package java.lang.reflect;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * @author Per Bothner <bothner@cygnus.com>
|
---|
15 | * @date january 12, 1999
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3.
|
---|
19 | * Status: Believe complete and correct.
|
---|
20 | */
|
---|
21 |
|
---|
22 | public final class Array
|
---|
23 | {
|
---|
24 | Array () { }
|
---|
25 |
|
---|
26 | public static native Object newInstance(Class componentType, int length);
|
---|
27 | public static native Object newInstance(Class elementType, int[] dimensions);
|
---|
28 | public static native int getLength (Object array);
|
---|
29 |
|
---|
30 | public static native Object get (Object array, int index);
|
---|
31 | public static native char getChar (Object array, int index);
|
---|
32 | public static native byte getByte (Object array, int index);
|
---|
33 | public static native short getShort (Object array, int index);
|
---|
34 | public static native int getInt (Object array, int index);
|
---|
35 | public static native long getLong (Object array, int index);
|
---|
36 | public static native float getFloat (Object array, int index);
|
---|
37 | public static native double getDouble (Object array, int index);
|
---|
38 | public static native boolean getBoolean (Object array, int index);
|
---|
39 |
|
---|
40 | private static native Class getElementType (Object array, int index);
|
---|
41 |
|
---|
42 | private static native void set (Object array, int index,
|
---|
43 | Object value, Class elType);
|
---|
44 |
|
---|
45 | public static void set (Object array, int index, Object value)
|
---|
46 | {
|
---|
47 | Class elType = getElementType(array, index);
|
---|
48 | if (! elType.isPrimitive())
|
---|
49 | set(array, index, value, elType);
|
---|
50 | else if (value instanceof Byte)
|
---|
51 | setByte(array, index, ((Byte) value).byteValue());
|
---|
52 | else if (value instanceof Short)
|
---|
53 | setShort (array, index, ((Short) value).shortValue());
|
---|
54 | else if (value instanceof Integer)
|
---|
55 | setInt(array, index, ((Integer) value).intValue());
|
---|
56 | else if (value instanceof Long)
|
---|
57 | setLong(array, index, ((Long) value).longValue());
|
---|
58 | else if (value instanceof Float)
|
---|
59 | setFloat(array, index, ((Float) value).floatValue());
|
---|
60 | else if (value instanceof Double)
|
---|
61 | setDouble(array, index, ((Double) value).doubleValue());
|
---|
62 | else if (value instanceof Character)
|
---|
63 | setChar(array, index, ((Character) value).charValue());
|
---|
64 | else if (value instanceof Boolean)
|
---|
65 | setBoolean(array, index, ((Boolean) value).booleanValue());
|
---|
66 | else
|
---|
67 | throw new IllegalArgumentException();
|
---|
68 | }
|
---|
69 |
|
---|
70 | public static native void setByte (Object array, int index, byte value);
|
---|
71 | public static native void setShort (Object array, int index, short value);
|
---|
72 | public static native void setInt (Object array, int index, int value);
|
---|
73 | public static native void setLong (Object array, int index, long value);
|
---|
74 | public static native void setFloat (Object array, int index, float value);
|
---|
75 | public static native void setDouble (Object array, int index, double value);
|
---|
76 | public static native void setChar (Object array, int index, char value);
|
---|
77 | public static native void setBoolean(Object array, int index, boolean value);
|
---|
78 | }
|
---|