use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.
the class MathUtils method subtraction.
public static IEntity subtraction(IEntity result1, IEntity result2) {
DataKinds dataKind1 = DataTypeUtils.getUnboxedDataKind(result1);
DataKinds dataKind2 = DataTypeUtils.getUnboxedDataKind(result2);
IEntity result;
if (dataKind1.isNotAData() || dataKind2.isNotAData())
throw new WholeIllegalArgumentException(WholeMessages.no_data);
else if (dataKind1.isDouble() || dataKind2.isDouble())
result = BindingManagerFactory.instance.createValue(DataTypeUtils.toDouble(result1) - DataTypeUtils.toDouble(result2));
else if (dataKind1.isFloat() || dataKind2.isFloat())
result = BindingManagerFactory.instance.createValue(DataTypeUtils.toFloat(result1) - DataTypeUtils.toFloat(result2));
else if (dataKind1.isLong() || dataKind2.isLong())
result = BindingManagerFactory.instance.createValue(DataTypeUtils.toLong(result1) - DataTypeUtils.toLong(result2));
else
result = BindingManagerFactory.instance.createValue(DataTypeUtils.toInt(result1) - DataTypeUtils.toInt(result2));
return result;
}
use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.
the class MathUtils method multiplication.
public static IEntity multiplication(IEntity result1, IEntity result2) {
DataKinds dataKind1 = DataTypeUtils.getUnboxedDataKind(result1);
DataKinds dataKind2 = DataTypeUtils.getUnboxedDataKind(result2);
IEntity result;
if (dataKind1.isNotAData() || dataKind2.isNotAData())
throw new WholeIllegalArgumentException(WholeMessages.no_data);
else if (dataKind1.isDouble() || dataKind2.isDouble())
result = BindingManagerFactory.instance.createValue(DataTypeUtils.toDouble(result1) * DataTypeUtils.toDouble(result2));
else if (dataKind1.isFloat() || dataKind2.isFloat())
result = BindingManagerFactory.instance.createValue(DataTypeUtils.toFloat(result1) * DataTypeUtils.toFloat(result2));
else if (dataKind1.isLong() || dataKind2.isLong())
result = BindingManagerFactory.instance.createValue(DataTypeUtils.toLong(result1) * DataTypeUtils.toLong(result2));
else
result = BindingManagerFactory.instance.createValue(DataTypeUtils.toInt(result1) * DataTypeUtils.toInt(result2));
return result;
}
use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.
the class GenericBuilderContext method wEntity.
public void wEntity(EntityDescriptor<?> entityDesc, String value) {
DataKinds dataKind = entityDesc.getDataKind();
// FIXME workaround move responsibility into generated spec builder adapters
if (dataKind.isString())
builderStrategy.wEntity(entityDesc, value);
else {
IDataTypeParser dataTypeParser = DataTypeUtils.getDataTypeParser(entityDesc, DataTypeParsers.PERSISTENCE);
switch(dataKind) {
case DATE:
builderStrategy.wEntity(entityDesc, dataTypeParser.parseDate(entityDesc, value));
break;
case ENUM_VALUE:
builderStrategy.wEntity(entityDesc, dataTypeParser.parseEnumValue(entityDesc, value));
break;
case OBJECT:
builderStrategy.wEntity(entityDesc, dataTypeParser.parseObject(entityDesc, value));
break;
}
}
wNext();
}
use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.
the class MathInterpreterVisitor method visit.
@Override
public void visit(Root entity) {
IEntity result1 = evaluate(entity.getExpression());
IEntity result2 = evaluate(entity.getDegree());
DataKinds dataKind2 = DataTypeUtils.getUnboxedDataKind(result2);
// ToKind resultKind = maxKind(ToKind.INT, result1);
IEntity result;
if (dataKind2.isInt() && result2.wIntValue() == 2)
result = createDoubleLiteral(Math.sqrt(DataTypeUtils.toDouble(result1)));
else if (dataKind2.isInt() && result2.wIntValue() == 3)
result = createDoubleLiteral(Math.cbrt(DataTypeUtils.toDouble(result1)));
else
result = createDoubleLiteral(Math.pow(DataTypeUtils.toDouble(result1), 1.0 / DataTypeUtils.toDouble(result2)));
setResult(result);
}
use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.
the class MathInterpreterVisitor method visit.
@Override
public void visit(ExclusiveOr entity) {
boolean value = false;
for (int i = 0, size = entity.size(); i < size; i++) {
IEntity result = evaluate(entity.get(i));
DataKinds dataKinds = DataTypeUtils.getUnboxedDataKind(result);
if (dataKinds.isNotAData())
throw new WholeIllegalArgumentException(WholeMessages.no_data).withSourceEntity(entity).withBindings(getBindings());
else if (!dataKinds.isBoolean())
throw new WholeIllegalArgumentException(WholeMessages.illegal_data_conversion).withSourceEntity(entity).withBindings(getBindings());
else
value ^= result.wBooleanValue();
}
setResult(createBooleanLiteral(value));
}
Aggregations