/** * Gets the field value. * * @return the value of the field */ public Object value() { if (!convert1st) { FieldAccess field = field(); if (field != null) { switch (field.typeEnum()) { case NUMBER: this.value = (VALUE) Conversions.coerce(field.type(), this.value); return new MyNumber(this.value); case ARRAY: case ARRAY_INT: case ARRAY_BYTE: case ARRAY_SHORT: case ARRAY_FLOAT: case ARRAY_DOUBLE: case ARRAY_LONG: case ARRAY_STRING: case ARRAY_OBJECT: case COLLECTION: case SET: case LIST: this.value = (VALUE) Conversions.coerce(field.getComponentClass(), this.value); break; default: this.value = (VALUE) Conversions.coerce(field.type(), this.value); } } convert1st = true; } return value; }
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 * @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; }
/** * Gets the field value. * * @return the value of the field */ public Object value2() { if (!convert2nd) { FieldAccess field = this.field(); this.value2 = (VALUE) Conversions.coerce(field.type(), this.value2); convert2nd = true; } return value2; }
public char fieldChar() { if (!path) { FieldAccess field1 = this.field(); return field1.getChar(objectUnderTest); } else { return BeanUtils.idxChar(objectUnderTest, name.toString()); } }
public long fieldLong() { if (!path) { FieldAccess field1 = this.field(); return field1.getLong(objectUnderTest); } else { return BeanUtils.idxLong(objectUnderTest, name.toString()); } }
public int fieldInt() { if (!path) { FieldAccess field1 = this.field(); return field1.getInt(objectUnderTest); } else { return BeanUtils.idxInt(objectUnderTest, name.toString()); } }
public byte fieldByte() { if (!path) { FieldAccess field1 = this.field(); return field1.getByte(objectUnderTest); } else { return BeanUtils.idxByte(objectUnderTest, name.toString()); } }
/** * Gets the field value. * * @return the value of the field */ public Object fieldValue() { if (!path) { FieldAccess field1 = this.field(); return field1.getValue(objectUnderTest); } else { return BeanUtils.atIndex(objectUnderTest, name.toString()); } }
/** * Gets the field value. * * @return the value of the field */ public Object value() { if (!convert1st) { FieldAccess field = field(); if (field != null) { switch (field.typeEnum()) { case ARRAY: case COLLECTION: case SET: case LIST: this.value = (VALUE) Conversions.coerce(field.getComponentClass(), this.value); break; default: this.value = (VALUE) Conversions.coerce(field.type(), this.value); } } convert1st = true; } return value; }
public Set<Object> valueSet() { if (!convert1st) { HashSet<Object> set = new HashSet<>(values.length); FieldAccess field = this.field(); Class<?> classType = field.type(); for (Object v : values) { v = Conversions.coerce(classType, this.value); set.add(v); } value = (VALUE) set; convert1st = true; } return (Set<Object>) value; }
private void initIfNeeded() { if (initialized) return; initialized = true; String name = this.name.toString(); FieldAccess field = field(); if (field == null) { return; } Class type = field.type(); if (!type.isPrimitive() && type != Typ.date) { return; } if (type == Typ.date) { if (!(value instanceof Date)) { initForDate(); } return; } useDelegate = true; if (type == Typ.intgr) { int v = Conversions.toInt(value); initForInt(v); } else if (type == Typ.bt) { byte v = Conversions.toByte(value); initForByte(v); } else if (type == Typ.shrt) { short v = Conversions.toShort(value); initForShortValue(v); } else if (type == Typ.lng) { long v = Conversions.toLong(value); initForLong(v); } else if (type == Typ.flt) { float v = Conversions.toFloat(value); initForFloat(v); } else if (type == Typ.dbl) { double v = Conversions.toDouble(value); initForDouble(v); } else if (type == Typ.bln) { switch (operator) { case EQUAL: nativeDelegate = ObjectFilter.eqBoolean(name, Conversions.toBoolean(value)); break; case NOT_EQUAL: nativeDelegate = ObjectFilter.notEqBoolean(name, Conversions.toBoolean(value)); break; default: useDelegate = false; } } else if (type == Typ.chr) { char v = Conversions.toChar(value); initForChar(v); } }