01: /**
02: * $Id: OrderedSet.java,v 1.2 2004/01/21 20:41:41 sathyakn Exp $
03: * Allrights reserved. Use of this product is subject to license terms.
04: * Federal Acquisitions: Commercial Software -- Government Users Subject
05: * to Standard License Terms and Conditions.
06: *
07: * Sun, Sun Microsystems, the Sun logo, and Sun ONE are trademarks or
08: * registered trademarks of Sun Microsystems,Inc. in the United States
09: * and other countries.
10: */
11:
12: /**
13: * <p>The <CODE>OrderedSet</CODE> class implements the AbtsractSet
14: * to return an ordered set of elements. The order is the order in
15: * which the elements were added in. To do this the OrederedSet is
16: * backed by a List. The data is unsynchronized.
17: */package com.sun.mobile.cdm;
18:
19: import java.util.List;
20: import java.util.ArrayList;
21: import java.util.AbstractSet;
22: import java.util.Collection;
23: import java.util.Iterator;
24:
25: public class OrderedSet extends AbstractSet {
26: //
27: // To store the elements in order.
28: //
29: private List list = null;
30:
31: public OrderedSet() {
32: list = new ArrayList();
33: }
34:
35: public OrderedSet(Collection c) {
36: list = new ArrayList(c.size());
37: list.addAll(c);
38: }
39:
40: public OrderedSet(int size) {
41: list = new ArrayList(size);
42: }
43:
44: public boolean add(Object o) {
45: boolean added = false;
46:
47: if (!list.contains(o)) {
48: list.add(o);
49: added = true;
50: }
51:
52: return added;
53: }
54:
55: public Iterator iterator() {
56: return list.iterator();
57: }
58:
59: public int size() {
60: return list.size();
61: }
62: }
|