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