Search in sources :

Example 6 with DataKinds

use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.

the class ContentAssistOperation method visit.

@Override
public void visit(IEntity entity) {
    EntityDescriptor<?> entityEd = entity.wGetEntityDescriptor();
    DataKinds dataKind = entityEd.getDataKind();
    // TODO merge with parent results if different language
    if (dataKind.isNotAData()) {
        IEntity parent = entity.wGetParent();
        if (!EntityUtils.isNull(parent)) {
            entityEd = parent.wGetEntityDescriptor(entity);
            dataKind = entityEd.getDataKind();
        }
    }
    final EntityDescriptor<?> ed = entityEd;
    switch(dataKind) {
        case ENUM_VALUE:
            final List<EnumValue> enumValues = new ArrayList<EnumValue>(ed.getDataEnumType().values());
            final IDataTypeParser unparser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
            Collections.sort(enumValues, (EnumValue arg0, EnumValue arg1) -> {
                String arg0String = unparser.unparseEnumValue(ed, arg0);
                String arg1String = unparser.unparseEnumValue(ed, arg1);
                if (arg0String.length() == 0 || arg1String.length() == 0 || !Character.isLetterOrDigit(arg0String.charAt(0)) || !Character.isLetterOrDigit(arg1String.charAt(0)))
                    return arg0.compareTo(arg1);
                else
                    return arg0String.compareTo(arg1String);
            });
            int size = enumValues.size();
            IEntity[] values = new IEntity[size];
            for (int i = 0; i < size; i++) values[i] = GenericEntityFactory.instance.create(ed, enumValues.get(i));
            setResult(values);
            break;
        case BOOLEAN:
            setResult(new IEntity[] { GenericEntityFactory.instance.create(ed, true), GenericEntityFactory.instance.create(ed, false) });
            break;
        default:
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) EnumValue(org.whole.lang.model.EnumValue) ArrayList(java.util.ArrayList) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) DataKinds(org.whole.lang.reflect.DataKinds)

Example 7 with DataKinds

use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.

the class MathUtils method greaterOrEquals.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static IEntity greaterOrEquals(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 8 with DataKinds

use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.

the class MathUtils method greaterThan.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static IEntity greaterThan(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 9 with DataKinds

use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.

the class MathUtils method lessOrEquals.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static IEntity lessOrEquals(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 10 with DataKinds

use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.

the class MathUtils method remainder.

public static IEntity remainder(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)

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