01: /*
02: * iterable.java
03: *
04: * Copyright (c) 2006 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.Context;
12: import pnuts.lang.Generator;
13: import pnuts.lang.PnutsFunction;
14:
15: public class iterable extends PnutsFunction {
16:
17: public iterable() {
18: super ("iterable");
19: }
20:
21: public boolean defined(int narg) {
22: return (narg == 1);
23: }
24:
25: protected Object exec(Object[] args, Context context) {
26: if (args.length == 1) {
27: Object obj = args[0];
28: return (obj instanceof Generator)
29: || (context.getConfiguration().toEnumeration(obj) != null) ? Boolean.TRUE
30: : Boolean.FALSE;
31: } else {
32: undefined(args, context);
33: return null;
34: }
35: }
36:
37: public String toString() {
38: return "function iterable(obj)";
39: }
40: }
|