KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > functions > CountValues


1 // Copyright (c) 2001 Per M.A. Bothner and Brainfood Inc.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.kawa.functions;
5 import gnu.mapping.*;
6 import gnu.lists.Consumer;
7
8 /** Return the number of values in the argument. */
9
10 public class CountValues extends Procedure1
11 {
12   public static final CountValues countValues = new CountValues();
13
14   public static int countValues(Object JavaDoc arg)
15   {
16     return arg instanceof Values ? ((Values) arg).size() : 1;
17   }
18
19   public Object JavaDoc apply1(Object JavaDoc arg)
20   {
21     return gnu.math.IntNum.make(countValues(arg));
22   }
23
24   public void apply (CallContext ctx)
25   {
26     Consumer consumer = ctx.consumer;
27     Object JavaDoc arg = ctx.getNextArg();
28     ctx.lastArg();
29     consumer.writeInt(countValues(arg));
30   }
31 }
32
33
Popular Tags