01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05:
06: package com.sun.portal.search.util;
07:
08: import java.util.*;
09: import java.io.*;
10:
11: /**
12: * A HashMap keeps keys in original order
13: */
14: public class OrderedMap extends HashMap {
15:
16: private ArrayList orderedKeys = new ArrayList();
17:
18: public Object put(Object key, Object value) {
19: Object item = super .put(key, value);
20: if (item == null) {
21: orderedKeys.add(key);
22: }
23: return item;
24: }
25:
26: public Object remove(Object key) {
27: Object item = super .remove(key);
28: orderedKeys.remove(key);
29: return item;
30: }
31:
32: public String[] getOrderedKeys() {
33: return (String[]) orderedKeys.toArray(new String[0]);
34: }
35:
36: }
|