01: // Copyright (c) 2001 Per M.A. Bothner and Brainfood Inc.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.kawa.functions;
05:
06: import gnu.mapping.*;
07: import gnu.lists.Consumer;
08:
09: /** Return the number of values in the argument. */
10:
11: public class CountValues extends Procedure1 {
12: public static final CountValues countValues = new CountValues();
13:
14: public static int countValues(Object arg) {
15: return arg instanceof Values ? ((Values) arg).size() : 1;
16: }
17:
18: public Object apply1(Object arg) {
19: return gnu.math.IntNum.make(countValues(arg));
20: }
21:
22: public void apply(CallContext ctx) {
23: Consumer consumer = ctx.consumer;
24: Object arg = ctx.getNextArg();
25: ctx.lastArg();
26: consumer.writeInt(countValues(arg));
27: }
28: }
|