Search in sources :

Example 16 with DataKinds

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;
}
Also used : IEntity(org.whole.lang.model.IEntity) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Example 17 with DataKinds

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;
}
Also used : IEntity(org.whole.lang.model.IEntity) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Example 18 with DataKinds

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();
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) DataKinds(org.whole.lang.reflect.DataKinds)

Example 19 with DataKinds

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);
}
Also used : IEntity(org.whole.lang.model.IEntity) DataKinds(org.whole.lang.reflect.DataKinds)

Example 20 with DataKinds

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));
}
Also used : IEntity(org.whole.lang.model.IEntity) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Aggregations

DataKinds (org.whole.lang.reflect.DataKinds)22 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)17 IEntity (org.whole.lang.model.IEntity)12 IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)3 ArrayList (java.util.ArrayList)1 EnumValue (org.whole.lang.model.EnumValue)1