01: /*
02: * @(#)loopEnum.java 1.2 04/12/06
03: *
04: * Copyright (c) 2001-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.util;
10:
11: import pnuts.lang.*;
12: import java.util.Enumeration;
13:
14: /*
15: * function loopEnum(n)
16: */
17: public class loopEnum extends PnutsFunction {
18:
19: public loopEnum() {
20: super ("loopEnum");
21: }
22:
23: public boolean defined(int nargs) {
24: return nargs == 1;
25: }
26:
27: protected Object exec(Object[] args, Context context) {
28: int nargs = args.length;
29: if (nargs == 1) {
30: final int max = ((Integer) args[0]).intValue();
31:
32: class Enum implements Enumeration {
33: int n = max;
34:
35: public boolean hasMoreElements() {
36: return n > 0;
37: }
38:
39: public Object nextElement() {
40: n--;
41: return null;
42: }
43: }
44: return new Enum();
45:
46: } else {
47: undefined(args, context);
48: return null;
49: }
50: }
51:
52: public String toString() {
53: return "function loopEnum(n)";
54: }
55: }
|