01: /*
02: * @(#)count.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.lib;
10:
11: import pnuts.lang.*;
12: import pnuts.lang.Runtime;
13: import java.io.*;
14: import java.util.*;
15: import java.lang.reflect.*;
16:
17: public class count extends PnutsFunction {
18:
19: private static Counter counter;
20: private static String stringRepresentation;
21: static {
22: try {
23: Class.forName("java.lang.CharSequence");
24: counter = new MerlinCounter();
25: stringRepresentation = "function count(InputStream|Reader|CharSequence|File|Collection|array|Enumeration|Iterator|Generator)";
26: } catch (Exception e) {
27: counter = new Counter();
28: stringRepresentation = "function count(InputStream|Reader|String|File|Collection|array|Enumeration|Iterator|Generator)";
29: }
30: }
31:
32: public count() {
33: super ("count");
34: }
35:
36: public boolean defined(int nargs) {
37: return nargs == 1;
38: }
39:
40: protected Object exec(Object[] args, Context context) {
41: if (args.length != 1) {
42: undefined(args, context);
43: return null;
44: }
45: Object a = args[0];
46: return counter.count(a, context);
47: }
48:
49: public String toString() {
50: return stringRepresentation;
51: }
52: }
|