/** * Get property value * * @param object object * @param path in dotted notation * @return int */ public static int idxInt( Object object, String path ) { String[] properties = propertyPathAsStringArray(path); return getPropertyInt( object, properties ); }
/** * Get property value * * @param object object * @param path in dotted notation * @return int */ public static int idxInt( Object object, String path ) { String[] properties = propertyPathAsStringArray(path); return getPropertyInt( object, properties ); }
public static double variance(Collection<?> inputList, String propertyPath) { double mean = mean(inputList, propertyPath); double temp = 0; double a; if (propertyPath.contains(".") || propertyPath.contains("[")) { String[] properties = StringScanner.splitByDelimiters(propertyPath, ".[]"); for (Object o : inputList) { a =BeanUtils.getPropertyInt(o, properties); temp += (mean-a)*(mean-a); } } else { Map<String, FieldAccess> fields = BeanUtils.getFieldsFromObject(inputList.iterator().next()); FieldAccess fieldAccess = fields.get(propertyPath); for (Object o : inputList) { a = fieldAccess.getInt(o); temp += (mean-a)*(mean-a); } } return Math.round(temp / inputList.size()); }
/** * Calculate a sum of a property from a list. * @param inputList input list * @param propertyPath to item we want to sum * @return sum */ public static long sum( Collection<?> inputList, String propertyPath ) { if (inputList.size() == 0 ) { return 0; } long sum = 0l; if (propertyPath.contains(".") || propertyPath.contains("[")) { String[] properties = StringScanner.splitByDelimiters(propertyPath, ".[]"); for (Object o : inputList) { sum+=BeanUtils.getPropertyInt(o, properties); } } else { Map<String, FieldAccess> fields = BeanUtils.getFieldsFromObject(inputList.iterator().next()); FieldAccess fieldAccess = fields.get(propertyPath); for (Object o : inputList) { sum += fieldAccess.getInt(o); } } return sum; }
/** * Calculate a sum of a property from a list. * @param inputList input list * @param propertyPath to item we want to sum * @return sum */ public static long sum( Collection<?> inputList, String propertyPath ) { if (inputList.size() == 0 ) { return 0; } long sum = 0l; if (propertyPath.contains(".") || propertyPath.contains("[")) { String[] properties = StringScanner.splitByDelimiters(propertyPath, ".[]"); for (Object o : inputList) { sum+=BeanUtils.getPropertyInt(o, properties); } } else { Map<String, FieldAccess> fields = BeanUtils.getFieldsFromObject(inputList.iterator().next()); FieldAccess fieldAccess = fields.get(propertyPath); for (Object o : inputList) { sum += fieldAccess.getInt(o); } } return sum; }
public static double variance(Collection<?> inputList, String propertyPath) { double mean = mean(inputList, propertyPath); double temp = 0; double a; if (propertyPath.contains(".") || propertyPath.contains("[")) { String[] properties = StringScanner.splitByDelimiters(propertyPath, ".[]"); for (Object o : inputList) { a =BeanUtils.getPropertyInt(o, properties); temp += (mean-a)*(mean-a); } } else { Map<String, FieldAccess> fields = BeanUtils.getFieldsFromObject(inputList.iterator().next()); FieldAccess fieldAccess = fields.get(propertyPath); for (Object o : inputList) { a = fieldAccess.getInt(o); temp += (mean-a)*(mean-a); } } return Math.round(temp / inputList.size()); }
/** * Creates a primitive list based on an input list and a property path * * @param inputList input list * @param propertyPath property path * @return primitive list */ public static IntList toIntList(Collection<?> inputList, String propertyPath) { if (inputList.size() == 0) { return new IntList(0); } IntList outputList = new IntList(inputList.size()); if (propertyPath.contains(".") || propertyPath.contains("[")) { String[] properties = StringScanner.splitByDelimiters(propertyPath, ".[]"); for (Object o : inputList) { outputList.add(BeanUtils.getPropertyInt(o, properties)); } } else { Map<String, FieldAccess> fields = BeanUtils.getFieldsFromObject(inputList.iterator().next()); FieldAccess fieldAccess = fields.get(propertyPath); for (Object o : inputList) { outputList.add(fieldAccess.getInt(o)); } } return outputList; }