package solutions.bitbadger.documents /** * A comparison against a field in a JSON document * * @property op The operation for the field comparison * @property value The value against which the comparison will be made */ class Comparison(val op: Op, val value: T) { /** Is the value for this comparison a numeric value? */ val isNumeric: Boolean get() { val toCheck = when (op) { Op.IN -> { val values = value as? Collection<*> if (values.isNullOrEmpty()) "" else values.elementAt(0) } Op.BETWEEN -> (value as Pair<*, *>).first else -> value } return toCheck is Byte || toCheck is Short || toCheck is Int || toCheck is Long } override fun toString() = "$op $value" }