KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > mapping > Procedure1or2


1 package gnu.mapping;
2
3 /**
4  * Abstract class for 1- or 2-argument Scheme procedures.
5  * Extensions must provide apply1 and apply2.
6  * @author Per Bothner
7  */

8
9 public abstract class Procedure1or2 extends Procedure
10 {
11
12   public Procedure1or2 ()
13   {
14     super();
15   }
16
17   public Procedure1or2 (String JavaDoc n)
18   {
19     super(n);
20   }
21
22   public int numArgs() { return 0x2001; }
23
24   public Object JavaDoc apply0 ()
25   {
26     throw new WrongArguments(this, 0);
27   }
28
29   public abstract Object JavaDoc apply1 (Object JavaDoc arg1) throws Throwable JavaDoc;
30
31   public abstract Object JavaDoc apply2 (Object JavaDoc arg1,Object JavaDoc arg2) throws Throwable JavaDoc;
32
33   public Object JavaDoc apply3 (Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3)
34   {
35     throw new WrongArguments(this, 3);
36   }
37
38   public Object JavaDoc apply4 (Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3, Object JavaDoc arg4)
39   {
40     throw new WrongArguments(this, 4);
41   }
42
43   public Object JavaDoc applyN (Object JavaDoc[] args) throws Throwable JavaDoc
44   {
45     if (args.length == 1)
46       return apply1 (args[0]);
47     else if (args.length == 2)
48       return apply2 (args[0], args[1]);
49     else
50       throw new WrongArguments(this, args.length);
51   }
52 }
53
Popular Tags