⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 array.java

📁 一个开源的JAVA虚拟机
💻 JAVA
字号:
/*    libaegisvm - The Aegis Virtual Machine for executing Java bytecode    Copyright (C) 2001-2002  Philip W. L. Fong    This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/package java.lang.reflect;public final class Array {    private Array() { }    private static int dimension(Class array) {	int count = 0;	while (array.isArray()) {	    count++;	    array = array.getComponentType();	}	return count;    }    public static native Object newInstance(Class componentType,					    int length)	throws NegativeArraySizeException;    public static native Object newInstance(Class componentType,					    int[] dimensions)	throws IllegalArgumentException, NegativeArraySizeException;    public native static int getLength(Object array)	throws IllegalArgumentException;    private native static Object getElement(Object array, int index);    public static Object get(Object array, int index)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	// The invocation of getLength() already checks if array is null	// and if array belongs to an array class.	if (index < 0 || index >= getLength(array))	    throw new ArrayIndexOutOfBoundsException();	return getElement(array, index);    }    public static boolean getBoolean(Object array, int index)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	Object value = get(array, index);	Class type = array.getClass().getComponentType();	return aegis.Reflect.widenToBoolean(type, value);    }    public static byte getByte(Object array, int index)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	Object value = get(array, index);	Class type = array.getClass().getComponentType();	return aegis.Reflect.widenToByte(type, value);    }    public static char getChar(Object array, int index)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	Object value = get(array, index);	Class type = array.getClass().getComponentType();	return aegis.Reflect.widenToCharacter(type, value);    }    public static short getShort(Object array, int index)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	Object value = get(array, index);	Class type = array.getClass().getComponentType();	return aegis.Reflect.widenToShort(type, value);    }    public static int getInt(Object array, int index)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	Object value = get(array, index);	Class type = array.getClass().getComponentType();	return aegis.Reflect.widenToInteger(type, value);    }    public static long getLong(Object array, int index)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	Object value = get(array, index);	Class type = array.getClass().getComponentType();	return aegis.Reflect.widenToLong(type, value);    }    public static float getFloat(Object array, int index)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	Object value = get(array, index);	Class type = array.getClass().getComponentType();	return aegis.Reflect.widenToFloat(type, value);    }    public static double getDouble(Object array, int index)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	Object value = get(array, index);	Class type = array.getClass().getComponentType();	return aegis.Reflect.widenToDouble(type, value);    }    private static native void setElement(Object array,					  int index,					  Object value);    public static void set(Object array, int index, Object value)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	// The invocation of getLength() already checks if array is null	// and if array belongs to an array class.	if (index < 0 || index >= getLength(array))	    throw new ArrayIndexOutOfBoundsException();	value = aegis.Reflect.widen(value,array.getClass().getComponentType());	setElement(array, index, value);    }    public static void setBoolean(Object array, int index, boolean z)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	set(array, index, new Boolean(z));    }    public static void setByte(Object array, int index, byte b)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	set(array, index, new Byte(b));    }    public static void setChar(Object array, int index, char c)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	set(array, index, new Character(c));    }    public static void setShort(Object array, int index, short s)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	set(array, index, new Short(s));    }    public static void setInt(Object array, int index, int i)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	set(array, index, new Integer(i));    }    public static void setLong(Object array, int index, long l)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	set(array, index, new Long(l));    }    public static void setFloat(Object array, int index, float f)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	set(array, index, new Float(f));    }    public static void setDouble(Object array, int index, double d)	throws IllegalArgumentException, ArrayIndexOutOfBoundsException {	set(array, index, new Double(d));    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -