01: /*
02: * @(#)pop.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 pop(linkedListOrStack)
17: */
18: public class pop extends PnutsFunction {
19:
20: public pop() {
21: super ("pop");
22: }
23:
24: public boolean defined(int nargs) {
25: return nargs == 1;
26: }
27:
28: protected Object exec(Object[] args, Context context) {
29: if (args.length != 1) {
30: undefined(args, context);
31: return null;
32: }
33: Object arg = args[0];
34: if (arg instanceof LinkedList) {
35: return ((LinkedList) args[0]).removeLast();
36: } else if (arg instanceof Stack) {
37: return ((Stack) args[0]).pop();
38: } else {
39: throw new IllegalArgumentException(String.valueOf(arg));
40: }
41: }
42:
43: public String toString() {
44: return "function pop(linkedListOrStack)";
45: }
46: }
|