01: /*
02: * ListReplaceCmd.java --
03: *
04: * This file tests replacement of elements in a TclList.
05: * The list created from a string is not copied so
06: * only the newely allocated list CObject will need
07: * to be added to the cleanup queue. The list created
08: * from an argument will duplicate the native object
09: * and the new list will need to be cleaned up. An
10: * empty list will need to be deallocated too.
11: *
12: * Copyright (c) 2002 by Mo DeJong
13: *
14: * See the file "license.terms" for information on usage and redistribution
15: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16: *
17: * RCS: @(#) $Id: ListReplaceCmd.java,v 1.2 2003/01/09 02:15:40 mdejong Exp $
18: */
19:
20: package tests;
21:
22: import tcl.lang.*;
23:
24: public class ListReplaceCmd implements Command {
25: public void cmdProc(Interp interp, TclObject[] objv)
26: throws TclException {
27: TclObject obj;
28:
29: if (objv.length == 2) {
30: obj = objv[1];
31: if (obj.isShared())
32: obj = obj.duplicate();
33: } else if (objv.length == 3) {
34: obj = TclList.newInstance();
35: TclList.append(interp, obj, TclString.newInstance("UNO"));
36: TclList.append(interp, obj, TclString.newInstance("2"));
37: TclList.append(interp, obj, TclString.newInstance("3"));
38: TclList.append(interp, obj, TclString.newInstance("4"));
39: TclList.append(interp, obj, TclString.newInstance("5"));
40: } else {
41: obj = TclString.newInstance("1 2 3 4 5");
42: }
43:
44: TclObject[] arr = { TclString.newInstance("two"),
45: TclString.newInstance("three"),
46: TclString.newInstance("four") };
47:
48: TclList.replace(interp, obj, 1, 3, arr, 0, 2);
49: return;
50: }
51: }
|