KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > kawa > standard > call_with_values


1 package kawa.standard;
2 import gnu.mapping.*;
3
4 public class call_with_values extends Procedure2
5 {
6   public static final call_with_values callWithValues = new call_with_values();
7   static { callWithValues.setName("call-with-values"); }
8
9   public static Object JavaDoc callWithValues (Procedure producer, Procedure consumer)
10      throws Throwable JavaDoc
11   {
12     Object JavaDoc values = producer.apply0();
13     if (values instanceof Values)
14       return ((Values) values).call_with(consumer);
15     else
16       return consumer.apply1(values);
17   }
18
19   public Object JavaDoc apply2 (Object JavaDoc producer, Object JavaDoc consumer) throws Throwable JavaDoc
20   {
21     return callWithValues((Procedure) producer, (Procedure) consumer);
22   }
23
24   public void apply (CallContext ctx) throws Throwable JavaDoc
25   {
26     Procedure.checkArgCount(this, 2);
27     Object JavaDoc[] args = ctx.getArgs();
28     Object JavaDoc values = ((Procedure) args[0]).apply0 ();
29     Procedure consumer = (Procedure) args[1];
30     if (values instanceof Values)
31       {
32     args = ((Values) values).getValues();
33     consumer.checkN(args, ctx);
34       }
35     else
36       {
37     consumer.check1(values, ctx);
38       }
39   }
40 }
41
42
43
Popular Tags