01: /*
02: * @(#)push.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:
13: import java.util.*;
14:
15: /*
16: * function push(list, elem)
17: */
18: public class push extends PnutsFunction {
19:
20: public push() {
21: super ("push");
22: }
23:
24: public boolean defined(int nargs) {
25: return nargs == 2;
26: }
27:
28: protected Object exec(Object[] args, Context context) {
29: if (args.length != 2) {
30: undefined(args, context);
31: return null;
32: }
33: ((Collection) args[0]).add(args[1]);
34: return null;
35: }
36:
37: public String toString() {
38: return "function push(collection, elem)";
39: }
40: }
|