01: package gnu.mapping;
02:
03: /**
04: * Abstract class for 1- or 2-argument Scheme procedures.
05: * Extensions must provide apply1 and apply2.
06: * @author Per Bothner
07: */
08:
09: public abstract class Procedure1or2 extends Procedure {
10:
11: public Procedure1or2() {
12: super ();
13: }
14:
15: public Procedure1or2(String n) {
16: super (n);
17: }
18:
19: public int numArgs() {
20: return 0x2001;
21: }
22:
23: public Object apply0() {
24: throw new WrongArguments(this , 0);
25: }
26:
27: public abstract Object apply1(Object arg1) throws Throwable;
28:
29: public abstract Object apply2(Object arg1, Object arg2)
30: throws Throwable;
31:
32: public Object apply3(Object arg1, Object arg2, Object arg3) {
33: throw new WrongArguments(this , 3);
34: }
35:
36: public Object apply4(Object arg1, Object arg2, Object arg3,
37: Object arg4) {
38: throw new WrongArguments(this , 4);
39: }
40:
41: public Object applyN(Object[] args) throws Throwable {
42: if (args.length == 1)
43: return apply1(args[0]);
44: else if (args.length == 2)
45: return apply2(args[0], args[1]);
46: else
47: throw new WrongArguments(this, args.length);
48: }
49: }
|