01: /*
02: * SearchId.java
03: *
04: * Copyright (c) 1997 Sun Microsystems, Inc.
05: *
06: * See the file "license.terms" for information on usage and
07: * redistribution of this file, and for a DISCLAIMER OF ALL
08: * WARRANTIES.
09: *
10: * RCS: @(#) $Id: SearchId.java,v 1.3 2006/01/26 19:49:18 mdejong Exp $
11: *
12: */
13:
14: package tcl.lang;
15:
16: import java.util.*;
17:
18: /**
19: * SearchId is used only by the ArrayVar class. When searchstart is
20: * called on an Tcl array, a SearchId is created that contains the
21: * Enumerated list of all the array keys; a String that uniquely
22: * identifies the searchId for the Tcl array, and an index that is
23: * used when to generate other unique strings.
24: */
25: class SearchId {
26:
27: /**
28: * An Enumeration that stores the list of keys for
29: * the ArrayVar.
30: */
31: private Iterator iter;
32:
33: /**
34: * The unique searchId string
35: */
36: private String str;
37:
38: /**
39: * Unique index used for generating unique searchId strings
40: */
41: private int index;
42:
43: /**
44: * A SearchId is only created from an ArrayVar object. The ArrayVar
45: * constructs a new SearchId object by passing it's current keys
46: * stored as an enumeration, a unique string that ArrayVar creates,
47: * and an index value used for future SearchId objects.
48: *
49: * @param e initial Enumeration
50: * @param s String as the unique identifier for the searchId
51: * @param e index value for this object
52: */
53: SearchId(Iterator iter, String s, int i) {
54: this .iter = iter;
55: str = s;
56: index = i;
57: }
58:
59: /**
60: * Return the str that is the unique identifier of the SearchId
61: */
62: public String toString() {
63: return str;
64: }
65:
66: /**
67: * Return the Iterator for the SearchId object. This is
68: * used in the ArrayCmd class for the anymore, donesearch,
69: * and nextelement functions.
70: *
71: * @param none
72: * @return The Iterator for the SearchId object
73: */
74: Iterator getIterator() {
75: return iter;
76: }
77:
78: /**
79: * Return the integer value of the index. Used in ArrayVar to
80: * generate the next unique SearchId string.
81: *
82: * @param none
83: * @returnh The integer value of the index
84: */
85: int getIndex() {
86: return index;
87: }
88:
89: /**
90: * Tests for equality based on the value of str
91: * @param none
92: * @return boolean based on the equality of the string
93: */
94: boolean equals(String s) {
95: return str.equals(s);
96: }
97: }
|