Procedure0.java 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package gnu.mapping;
  2. /* #ifdef use:java.lang.invoke */
  3. import java.lang.invoke.*;
  4. /* #else */
  5. // import gnu.mapping.CallContext.MethodHandle;
  6. /* #endif */
  7. /**
  8. * Abstract class for 0-argument procedures.
  9. * @author Per Bothner
  10. */
  11. public abstract class Procedure0 extends Procedure
  12. {
  13. public Procedure0() {
  14. super(false, Procedure0.applyToObject);
  15. }
  16. public Procedure0(String name) {
  17. super(false, Procedure0.applyToObject, name);
  18. }
  19. public int numArgs() { return 0; }
  20. public abstract Object apply0 () throws Throwable;
  21. public Object apply1 (Object arg1)
  22. {
  23. throw new WrongArguments(this, 1);
  24. }
  25. public Object apply2 (Object arg1,Object arg2)
  26. {
  27. throw new WrongArguments(this, 2);
  28. }
  29. public Object apply3 (Object arg1, Object arg2, Object arg3)
  30. {
  31. throw new WrongArguments(this, 3);
  32. }
  33. public Object apply4 (Object arg1, Object arg2,
  34. Object arg3, Object arg4)
  35. {
  36. throw new WrongArguments(this, 4);
  37. }
  38. public Object applyN (Object[] args) throws Throwable
  39. {
  40. if (args.length != 0)
  41. throw new WrongArguments(this, args.length);
  42. return apply0 ();
  43. }
  44. public static Object applyToObject(Procedure proc, CallContext ctx)
  45. throws Throwable {
  46. if (ctx.checkDone() == 0)
  47. return proc.apply0();
  48. return ctx;
  49. }
  50. public static final MethodHandle applyToObject
  51. = lookupApplyHandle(Procedure0.class, "applyToObject");
  52. }