Search in sources :

Example 16 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class MathUtils method lessThan.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static IEntity lessThan(IEntity result1, IEntity result2) {
    DataKinds dataKind1 = DataTypeUtils.getUnboxedDataKind(result1);
    DataKinds dataKind2 = DataTypeUtils.getUnboxedDataKind(result2);
    boolean result;
    if (dataKind1.isNotAData() || dataKind2.isNotAData())
        throw new WholeIllegalArgumentException(WholeMessages.no_data);
    else if (dataKind1.isObject() && dataKind2.isObject()) {
        Object result1value = result1.wGetValue();
        Object result2value = result2.wGetValue();
        if (result1value instanceof Comparable && result2value instanceof Comparable)
            try {
                result = 0 > ((Comparable) result1value).compareTo((Comparable) result2value);
            } catch (ClassCastException e) {
                throw new IllegalArgumentException("Objects are not Comparable");
            }
        else
            throw new IllegalArgumentException("Objects are not Comparable");
    } else if (dataKind1.isEnumValue() && dataKind2.isEnumValue())
        result = 0 > result1.wEnumValue().compareTo(result2.wEnumValue());
    else if (dataKind1.isDate() && dataKind2.isDate())
        result = 0 > result1.wDateValue().compareTo(result2.wDateValue());
    else if (dataKind1.isString() || dataKind2.isString())
        result = 0 > DataTypeUtils.toString(result1).compareTo(DataTypeUtils.toString(result2));
    else if (dataKind1.isDouble() || dataKind2.isDouble())
        result = 0 > Double.compare(DataTypeUtils.toDouble(result1), DataTypeUtils.toDouble(result2));
    else if (dataKind1.isFloat() || dataKind2.isFloat())
        result = 0 > Float.compare(DataTypeUtils.toFloat(result1), DataTypeUtils.toFloat(result2));
    else if (dataKind1.isLong() || dataKind2.isLong())
        result = DataTypeUtils.toLong(result1) < DataTypeUtils.toLong(result2);
    else
        result = DataTypeUtils.toInt(result1) < DataTypeUtils.toInt(result2);
    return BindingManagerFactory.instance.createValue(result);
}
Also used : WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Example 17 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class MathUtils method division.

public static IEntity division(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 WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class MathUtils method notEquals.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static IEntity notEquals(IEntity result1, IEntity result2) {
    DataKinds dataKind1 = DataTypeUtils.getUnboxedDataKind(result1);
    DataKinds dataKind2 = DataTypeUtils.getUnboxedDataKind(result2);
    boolean result;
    if (dataKind1.isNotAData() || dataKind2.isNotAData())
        throw new WholeIllegalArgumentException(WholeMessages.no_data);
    else if (dataKind1.isBoolean() && dataKind2.isBoolean())
        result = DataTypeUtils.toBoolean(result1) != DataTypeUtils.toBoolean(result2);
    else if (dataKind1.isObject() && dataKind2.isObject()) {
        Object result1value = result1.wGetValue();
        Object result2value = result2.wGetValue();
        if (result1value instanceof Comparable<?> && result2value instanceof Comparable<?>)
            try {
                result = 0 != ((Comparable) result1value).compareTo((Comparable) result2value);
            } catch (ClassCastException e) {
                result = result1value != result2value;
            }
        else
            result = result1value != result2value;
    } else if (dataKind1.isEnumValue() && dataKind2.isEnumValue())
        result = !result1.wEnumValue().equals(result2.wEnumValue());
    else if (dataKind1.isDate() && dataKind2.isDate())
        result = !result1.wDateValue().equals(result2.wDateValue());
    else if (dataKind1.isString() || dataKind2.isString())
        result = !DataTypeUtils.toString(result1).equals(DataTypeUtils.toString(result2));
    else if (dataKind1.isDouble() || dataKind2.isDouble())
        result = 0 != Double.compare(DataTypeUtils.toDouble(result1), DataTypeUtils.toDouble(result2));
    else if (dataKind1.isFloat() || dataKind2.isFloat())
        result = 0 != Float.compare(DataTypeUtils.toFloat(result1), DataTypeUtils.toFloat(result2));
    else if (dataKind1.isLong() || dataKind2.isLong())
        result = DataTypeUtils.toLong(result1) != DataTypeUtils.toLong(result2);
    else
        result = DataTypeUtils.toInt(result1) != DataTypeUtils.toInt(result2);
    return BindingManagerFactory.instance.createValue(result);
}
Also used : WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Example 19 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class MathUtils method addition.

public static IEntity addition(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.isString() || dataKind2.isString())
        result = BindingManagerFactory.instance.createValue(DataTypeUtils.toString(result1) + DataTypeUtils.toString(result2));
    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 20 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class MathUtils method equals.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static IEntity equals(IEntity result1, IEntity result2) {
    DataKinds dataKind1 = DataTypeUtils.getUnboxedDataKind(result1);
    DataKinds dataKind2 = DataTypeUtils.getUnboxedDataKind(result2);
    boolean result;
    if (dataKind1.isNotAData() || dataKind2.isNotAData()) {
        result = false;
        if (!EntityUtils.isResolver(result1) && !EntityUtils.isResolver(result2))
            throw new WholeIllegalArgumentException(WholeMessages.no_data);
    } else if (dataKind1.isBoolean() && dataKind2.isBoolean())
        result = DataTypeUtils.toBoolean(result1) == DataTypeUtils.toBoolean(result2);
    else if (dataKind1.isObject() && dataKind2.isObject()) {
        Object result1value = result1.wGetValue();
        Object result2value = result2.wGetValue();
        if (result1value instanceof Comparable && result2value instanceof Comparable)
            try {
                result = 0 == ((Comparable) result1value).compareTo((Comparable) result2value);
            } catch (ClassCastException e) {
                result = result1value == result2value;
            }
        else
            result = result1value == result2value;
    } else if (dataKind1.isEnumValue() && dataKind2.isEnumValue())
        result = result1.wEnumValue().equals(result2.wEnumValue());
    else if (dataKind1.isDate() && dataKind2.isDate())
        result = result1.wDateValue().equals(result2.wDateValue());
    else if (dataKind1.isString() || dataKind2.isString())
        result = DataTypeUtils.toString(result1).equals(DataTypeUtils.toString(result2));
    else if (dataKind1.isDouble() || dataKind2.isDouble())
        result = 0 == Double.compare(DataTypeUtils.toDouble(result1), DataTypeUtils.toDouble(result2));
    else if (dataKind1.isFloat() || dataKind2.isFloat())
        result = 0 == Float.compare(DataTypeUtils.toFloat(result1), DataTypeUtils.toFloat(result2));
    else if (dataKind1.isLong() || dataKind2.isLong())
        result = DataTypeUtils.toLong(result1) == DataTypeUtils.toLong(result2);
    else
        result = DataTypeUtils.toInt(result1) == DataTypeUtils.toInt(result2);
    return BindingManagerFactory.instance.createValue(result);
}
Also used : WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Aggregations

WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)32 DataKinds (org.whole.lang.reflect.DataKinds)16 IEntity (org.whole.lang.model.IEntity)15 EnumValue (org.whole.lang.model.EnumValue)3 IBindingManager (org.whole.lang.bindings.IBindingManager)2 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)2 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)2 ILanguageKit (org.whole.lang.reflect.ILanguageKit)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 DateTimeZone (org.joda.time.DateTimeZone)1 DateTimeParser (org.joda.time.format.DateTimeParser)1 DateTimeParserBucket (org.joda.time.format.DateTimeParserBucket)1 FixedDateTimeZone (org.joda.time.tz.FixedDateTimeZone)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 URLPersistenceProvider (org.whole.lang.codebase.URLPersistenceProvider)1 IEntityFactory (org.whole.lang.factories.IEntityFactory)1 IEntityRegistryProvider (org.whole.lang.factories.IEntityRegistryProvider)1 CompiledPattern (org.whole.lang.grammars.model.CompiledPattern)1 Pattern (org.whole.lang.grammars.model.Pattern)1