List of usage examples for java.lang.reflect Array getFloat
public static native float getFloat(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
From source file:Main.java
public static void main(String args[]) { float[] array = new float[] { 1.1F, 2.2F, 3.3F }; float value = Array.getFloat(array, 1); System.out.println(value);//from w ww. ja v a 2s. c o m }
From source file:alice.tuprolog.lib.OOLibrary.java
/** * Sets the value of the field 'i' with 'what' * @param obj_id//from w w w .j a v a2 s .c o m * @param i * @param what * @return * @throws JavaException */ public boolean java_array_get_primitive_3(PTerm obj_id, PTerm i, PTerm what) throws JavaException { Struct objId = (Struct) obj_id.getTerm(); Number index = (Number) i.getTerm(); what = what.getTerm(); Object obj = null; if (!index.isInteger()) { throw new JavaException(new IllegalArgumentException(index.toString())); } try { Class<?> cl = null; String objName = alice.util.Tools.removeApices(objId.toString()); obj = currentObjects.get(objName); if (obj != null) { cl = obj.getClass(); } else { throw new JavaException(new IllegalArgumentException(objId.toString())); } if (!cl.isArray()) { throw new JavaException(new IllegalArgumentException(objId.toString())); } String name = cl.toString(); switch (name) { case "class [I": { PTerm value = new Int(Array.getInt(obj, index.intValue())); if (unify(what, value)) return true; else throw new JavaException(new IllegalArgumentException(what.toString())); } case "class [D": { PTerm value = new alice.tuprolog.Double(Array.getDouble(obj, index.intValue())); if (unify(what, value)) return true; else throw new JavaException(new IllegalArgumentException(what.toString())); } case "class [F": { PTerm value = new alice.tuprolog.Float(Array.getFloat(obj, index.intValue())); if (unify(what, value)) return true; else throw new JavaException(new IllegalArgumentException(what.toString())); } case "class [L": { PTerm value = new alice.tuprolog.Long(Array.getLong(obj, index.intValue())); if (unify(what, value)) return true; else throw new JavaException(new IllegalArgumentException(what.toString())); } case "class [C": { PTerm value = new Struct("" + Array.getChar(obj, index.intValue())); if (unify(what, value)) return true; else throw new JavaException(new IllegalArgumentException(what.toString())); } case "class [Z": boolean b = Array.getBoolean(obj, index.intValue()); if (b) { if (unify(what, PTerm.TRUE)) return true; else throw new JavaException(new IllegalArgumentException(what.toString())); } else { if (unify(what, PTerm.FALSE)) return true; else throw new JavaException(new IllegalArgumentException(what.toString())); } case "class [B": { PTerm value = new Int(Array.getByte(obj, index.intValue())); if (unify(what, value)) return true; else throw new JavaException(new IllegalArgumentException(what.toString())); } case "class [S": { PTerm value = new Int(Array.getInt(obj, index.intValue())); if (unify(what, value)) return true; else throw new JavaException(new IllegalArgumentException(what.toString())); } default: throw new JavaException(new Exception()); } } catch (Exception ex) { // ex.printStackTrace(); throw new JavaException(ex); } }
From source file:org.jgentleframework.core.interceptor.AnnotationAroundAdviceMethodInterceptor.java
/** * Hash code./* ww w . j a v a2s .c o m*/ * * @param proxy * the proxy * @return the int * @throws IllegalArgumentException * the illegal argument exception * @throws IllegalAccessException * the illegal access exception * @throws InvocationTargetException * the invocation target exception */ protected int hashCode(Object proxy) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Method[] methods = targetClass.getDeclaredMethods(); int hashCode = 0; for (Method method : methods) { Class<?> type = method.getReturnType(); Object value = (Object) this.attributesMapping.get(method); if (value == null) value = method.getDefaultValue(); // if type is primitive type if (type.isPrimitive()) { // ////////////////////////////////// // ////////////////////////////////// hashCode += 127 * method.getName().hashCode() ^ value.hashCode(); } else if (type.isArray()) { Object array = method.invoke(proxy); Class<?> comtype = type.getComponentType(); if (comtype == byte.class || comtype == Byte.class) { byte[] valueArr = new byte[Array.getLength(array)]; for (int i = 0; i < valueArr.length; i++) { valueArr[i] = Array.getByte(array, i); } hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr); } else if (comtype == char.class || comtype == Character.class) { char[] valueArr = new char[Array.getLength(array)]; for (int i = 0; i < valueArr.length; i++) { valueArr[i] = Array.getChar(array, i); } hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr); } else if (comtype == double.class || comtype == Double.class) { double[] valueArr = new double[Array.getLength(array)]; for (int i = 0; i < valueArr.length; i++) { valueArr[i] = Array.getDouble(array, i); } hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr); } else if (comtype == float.class || comtype == Float.class) { float[] valueArr = new float[Array.getLength(array)]; for (int i = 0; i < valueArr.length; i++) { valueArr[i] = Array.getFloat(array, i); } hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr); } else if (comtype == int.class || comtype == Integer.class) { int[] valueArr = new int[Array.getLength(array)]; for (int i = 0; i < valueArr.length; i++) { valueArr[i] = Array.getInt(array, i); } hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr); } else if (comtype == long.class || comtype == Long.class) { long[] valueArr = new long[Array.getLength(array)]; for (int i = 0; i < valueArr.length; i++) { valueArr[i] = Array.getLong(array, i); } hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr); } else if (comtype == short.class || comtype == Short.class) { short[] valueArr = new short[Array.getLength(array)]; for (int i = 0; i < valueArr.length; i++) { valueArr[i] = Array.getShort(array, i); } hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr); } else if (comtype == boolean.class || comtype == Boolean.class) { boolean[] valueArr = new boolean[Array.getLength(array)]; for (int i = 0; i < valueArr.length; i++) { valueArr[i] = Array.getBoolean(array, i); } hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr); } else { Object[] valueArr = new Object[Array.getLength(array)]; for (int i = 0; i < valueArr.length; i++) { valueArr[i] = Array.get(array, i); } hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr); } } else { // Object value = method.invoke(proxy); hashCode += 127 * method.getName().hashCode() ^ value.hashCode(); } } return hashCode; }