01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.rewriter.util.collections;
06:
07: import java.util.ArrayList;
08: import java.util.Collection;
09: import java.util.Collections;
10: import java.util.Iterator;
11: import java.util.Set;
12:
13: public class ListSet extends ArrayList implements Set {
14: public static final ListSet EMPTY_LISTSET = ListSet
15: .unmodifiableListSet(new ListSet(Collections.EMPTY_LIST));
16:
17: public ListSet() {
18: super ();
19: }//constructor
20:
21: public ListSet(final Collection c) {
22: super (c);
23: }//constructor
24:
25: public static ListSet unmodifiableListSet(final ListSet aListSet) {
26: return new ListSet(aListSet) {
27: public boolean add(final Object a) {
28: return Collections.EMPTY_LIST.add(a);
29: }
30: };
31: }//unmodifiableListSet()
32:
33: public boolean add(final Object a) {
34: if (this .contains(a)) {
35: return false;
36: }
37:
38: super .add(a);
39: return true;
40: }//add()
41:
42: public boolean addAll(final Collection a) {
43: boolean changed = false;
44: for (Iterator i = a.iterator(); i.hasNext();) {
45: if (this .add(i.next())) {
46: changed = true;
47: }
48: }
49: return changed;
50: }//addAll()
51: }//class ListSet
|