KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > OrderedSet


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment;
24
25 import java.util.*;
26
27     /** I am an ordered collection that does not allow duplicates.
28     *
29     * @author Danny Coward
30     */

31
32 class OrderedSet extends Vector implements Set {
33     
34     /** Construct an empty collection.
35     */

36     public OrderedSet() {
37     }
38
39     /** Construct an ordered set from the given collection.
40     */

41     public OrderedSet(Collection c) {
42         this();
43         this.addAll(c);
44     }
45
46     /**
47     * Add the given object to the Set if it is not equal (equals()) to
48     * an element already in the set.
49     */

50     public boolean add(Object JavaDoc o) {
51         if (o != null && !this.contains(o)) {
52         return super.add(o);
53         }
54         return false;
55     }
56     
57     /**
58     * Add all the elements in the given set that are not already
59     * in this ordered set.
60     */

61     public boolean addAll(Collection c) {
62         boolean setChanged = false;
63         if (c != null) {
64         for (Iterator itr = c.iterator(); itr.hasNext();) {
65             if (this.add(itr.next())) {
66             setChanged = true;
67             }
68         }
69         }
70         return setChanged;
71     }
72     
73     }
74
Popular Tags