01: /*
02: * @(#)size.java 1.4 05/06/14
03: *
04: * Copyright (c) 1997-2005 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:
13: public class size extends PnutsFunction {
14:
15: private static Counter counter;
16: private static String stringRepresentation;
17: static {
18: try {
19: Class.forName("java.lang.CharSequence");
20: counter = new MerlinCounter();
21: stringRepresentation = "function size(CharSequence|File|Collection|array";
22: } catch (Exception e) {
23: counter = new Counter();
24: stringRepresentation = "function size(String|File|Collection|array)";
25: }
26: }
27:
28: public size() {
29: super ("size");
30: }
31:
32: public boolean defined(int nargs) {
33: return nargs == 1;
34: }
35:
36: protected Object exec(Object[] args, Context context) {
37: if (args.length != 1) {
38: undefined(args, context);
39: return null;
40: }
41: Object a = args[0];
42: return counter.count(a, context);
43: }
44:
45: public String toString() {
46: return stringRepresentation;
47: }
48: }
|