protected static Value grind(RCvalue args, Operation op) throws EvalException { for (int i = 0; i < args.size(); i++) if (!(args.value(i) instanceof PolygonValue)) throw new EvalException( op.name() + "(): all operands must polgons." + "Operand " + (i + 1) + "is not."); return (grind(args, op, 0, args.size())); }
// value(lo) to value(hi-1) protected static Value grind(RCvalue args, Operation op, int lo, int hi) throws EvalException { switch (hi - lo) { case 0: return new PolygonValue( (RCvalue) (RCvalue.factory().create(new Value[] {}, true))); // empty case 1: return args.value(lo); // one case 2: Value result = op.op((PolygonValue) (args.value(lo)), (PolygonValue) (args.value(hi - 1))); return result; // two default: int mid = (lo + hi + 1) / 2; // split Value v0 = grind(args, op, lo, mid); Value v1 = grind(args, op, mid, hi); result = op.op((PolygonValue) (v0), (PolygonValue) (v1)); return result; } }