Search in sources :

Example 1 with GreaterOrEqual

use of org.polymap.recordstore.QueryExpression.GreaterOrEqual in project polymap4-core by Polymap4.

the class NumericValueCoder method searchQuery.

public Query searchQuery(QueryExpression exp) {
    // EQUALS
    if (exp instanceof QueryExpression.Equal) {
        Equal equalExp = (QueryExpression.Equal) exp;
        if (equalExp.value instanceof Number) {
            String key = equalExp.key;
            Number value = (Number) equalExp.value;
            if (equalExp.value instanceof Integer) {
                return NumericRangeQuery.newIntRange(key, value.intValue(), value.intValue(), true, true);
            } else if (equalExp.value instanceof Long) {
                return NumericRangeQuery.newLongRange(key, value.longValue(), value.longValue(), true, true);
            } else if (equalExp.value instanceof Float) {
                return NumericRangeQuery.newFloatRange(key, value.floatValue(), value.floatValue(), true, true);
            } else if (equalExp.value instanceof Double) {
                return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), value.doubleValue(), true, true);
            } else {
                throw new RuntimeException("Unknown Number type: " + value.getClass());
            }
        }
    } else // GREATER
    if (exp instanceof QueryExpression.Greater) {
        Greater greaterExp = (QueryExpression.Greater) exp;
        if (greaterExp.value instanceof Number) {
            String key = greaterExp.key;
            Number value = (Number) greaterExp.value;
            if (greaterExp.value instanceof Integer) {
                return NumericRangeQuery.newIntRange(key, value.intValue(), null, false, false);
            } else if (greaterExp.value instanceof Long) {
                return NumericRangeQuery.newLongRange(key, value.longValue(), null, false, false);
            } else if (greaterExp.value instanceof Float) {
                return NumericRangeQuery.newFloatRange(key, value.floatValue(), null, false, false);
            } else if (greaterExp.value instanceof Double) {
                return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), null, false, false);
            } else {
                throw new RuntimeException("Unknown Number type: " + value.getClass());
            }
        }
    } else // GREATER OR EQUAL
    if (exp instanceof QueryExpression.GreaterOrEqual) {
        GreaterOrEqual greaterExp = (QueryExpression.GreaterOrEqual) exp;
        if (greaterExp.value instanceof Number) {
            String key = greaterExp.key;
            Number value = (Number) greaterExp.value;
            if (greaterExp.value instanceof Integer) {
                return NumericRangeQuery.newIntRange(key, value.intValue(), null, true, false);
            } else if (greaterExp.value instanceof Long) {
                return NumericRangeQuery.newLongRange(key, value.longValue(), null, true, false);
            } else if (greaterExp.value instanceof Float) {
                return NumericRangeQuery.newFloatRange(key, value.floatValue(), null, true, false);
            } else if (greaterExp.value instanceof Double) {
                return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), null, true, false);
            } else {
                throw new RuntimeException("Unknown Number type: " + value.getClass());
            }
        }
    } else // LESS
    if (exp instanceof QueryExpression.Less) {
        Less lessExp = (QueryExpression.Less) exp;
        if (lessExp.value instanceof Number) {
            String key = lessExp.key;
            Number value = (Number) lessExp.value;
            if (lessExp.value instanceof Integer) {
                return NumericRangeQuery.newIntRange(key, null, value.intValue(), false, false);
            } else if (lessExp.value instanceof Long) {
                return NumericRangeQuery.newLongRange(key, null, value.longValue(), false, false);
            } else if (lessExp.value instanceof Float) {
                return NumericRangeQuery.newFloatRange(key, null, value.floatValue(), false, false);
            } else if (lessExp.value instanceof Double) {
                return NumericRangeQuery.newDoubleRange(key, null, value.doubleValue(), false, false);
            } else {
                throw new RuntimeException("Unknown Number type: " + value.getClass());
            }
        }
    } else // LESS or equal
    if (exp instanceof QueryExpression.LessOrEqual) {
        LessOrEqual lessExp = (QueryExpression.LessOrEqual) exp;
        if (lessExp.value instanceof Number) {
            String key = lessExp.key;
            Number value = (Number) lessExp.value;
            if (lessExp.value instanceof Integer) {
                return NumericRangeQuery.newIntRange(key, null, value.intValue(), false, true);
            } else if (lessExp.value instanceof Long) {
                return NumericRangeQuery.newLongRange(key, null, value.longValue(), false, true);
            } else if (lessExp.value instanceof Float) {
                return NumericRangeQuery.newFloatRange(key, null, value.floatValue(), false, true);
            } else if (lessExp.value instanceof Double) {
                return NumericRangeQuery.newDoubleRange(key, null, value.doubleValue(), false, true);
            } else {
                throw new RuntimeException("Unknown Number type: " + value.getClass());
            }
        }
    } else // MATCHES
    if (exp instanceof QueryExpression.Match) {
        Match matchExp = (Match) exp;
        if (matchExp.value instanceof Number) {
            throw new UnsupportedOperationException("MATCHES not supported for Number values.");
        }
    }
    return null;
}
Also used : Less(org.polymap.recordstore.QueryExpression.Less) LessOrEqual(org.polymap.recordstore.QueryExpression.LessOrEqual) GreaterOrEqual(org.polymap.recordstore.QueryExpression.GreaterOrEqual) Match(org.polymap.recordstore.QueryExpression.Match) Greater(org.polymap.recordstore.QueryExpression.Greater) Match(org.polymap.recordstore.QueryExpression.Match) BigInteger(java.math.BigInteger) Equal(org.polymap.recordstore.QueryExpression.Equal) LessOrEqual(org.polymap.recordstore.QueryExpression.LessOrEqual) GreaterOrEqual(org.polymap.recordstore.QueryExpression.GreaterOrEqual) Greater(org.polymap.recordstore.QueryExpression.Greater) QueryExpression(org.polymap.recordstore.QueryExpression) Less(org.polymap.recordstore.QueryExpression.Less)

Aggregations

BigInteger (java.math.BigInteger)1 QueryExpression (org.polymap.recordstore.QueryExpression)1 Equal (org.polymap.recordstore.QueryExpression.Equal)1 Greater (org.polymap.recordstore.QueryExpression.Greater)1 GreaterOrEqual (org.polymap.recordstore.QueryExpression.GreaterOrEqual)1 Less (org.polymap.recordstore.QueryExpression.Less)1 LessOrEqual (org.polymap.recordstore.QueryExpression.LessOrEqual)1 Match (org.polymap.recordstore.QueryExpression.Match)1