01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: * (C) 2002, Refractions Reserach Inc.
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation;
10: * version 2.1 of the License.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.graph.util;
18:
19: import java.util.HashMap;
20:
21: public class IndexedStack extends java.util.Stack {
22: private HashMap m_index; //object to index in stack
23:
24: public IndexedStack() {
25: super ();
26: m_index = new HashMap();
27: }
28:
29: public Object push(Object item) {
30: m_index.put(item, new Integer(size()));
31: return super .push(item);
32: }
33:
34: public Object pop() {
35: Object value = super .pop();
36: m_index.remove(value);
37: return (value);
38: }
39:
40: public boolean contains(Object elem) {
41: return (m_index.get(elem) != null);
42: }
43:
44: }
|