package gw.rating.rtm.matchop uses java.lang.Comparable uses java.lang.ArrayIndexOutOfBoundsException uses java.lang.IllegalArgumentException uses gw.api.util.TypeUtil uses gw.rating.rtm.domain.RowMinimizer.Minimizable uses gw.rating.rtm.domain.RowMinimizer class RangeParam implements CompoundParam, Minimizable { var _a : T as readonly First var _b : T as readonly Second var sval : String construct(v1 : T, v2 : T, toStringVal : String = null) { if (v1 == null and v2 == null) throw new IllegalArgumentException("Don't create a compound param that is all nulls") _a = v1 _b = v2 sval = toStringVal ?: "<<" + v1?.toString() + "," + v2?.toString() + ">>" } override function toString(): String { return sval } override property get NumValues() : int { return 2 } override function getValue(ix : int) : T { if (ix < 0 || ix > 1) throw new ArrayIndexOutOfBoundsException() return (ix == 0) ? First : Second } override function compareTo(o: CompoundParam) : int { if (this === o) return 0 var doCompare = \ a : Comparable, b : Comparable, signum : int = 1 -> { if (a === b) { // they're identical...nothing to see here return 0 } else { if (a == null) { return -1 * signum } else if (b == null) { return 1 * signum } else if (TypeUtil.isNominallyOrStructurallyAssignable(typeof a, typeof b)) { return a.compareTo(b) } else { throw new IllegalArgumentException("Cannot compare ${typeof a} and ${typeof b}") } } } var n = doCompare(this.First, o.First) if (n != 0) return n n = doCompare(this.Second, o.Second, -1) // if one of the pair is null, reverse sign if (n != 0) return n return (2 - o.NumValues) } override function equals(o : Object) : boolean { if (this === o) return true // this is better than .equals because 5!=5.000 var compareWithNullHandling = \a: Comparable, b: Comparable -> { if (a === b) { return true } else if (a == null || b == null) { return false } else if (TypeUtil.isNominallyOrStructurallyAssignable(typeof a, typeof b)) { return a.compareTo(b) == 0 } else { return false } } if (o typeis CompoundParam and o.NumValues == 2) { var doesFirstMatch = compareWithNullHandling(First, o.First) var doesSecondMatch = compareWithNullHandling(Second, o.Second) return doesFirstMatch && doesSecondMatch } else { return false } } override function hashCode(): int { return MultipleParam.computeHash({First, Second}) } override function minimize(m: RowMinimizer) { _a = m.minimize(_a) _b = m.minimize(_b) sval = m.minimize(sval) } }