KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > common > util > UniqueEList


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: UniqueEList.java,v 1.3 2005/06/08 06:19:08 nickb Exp $
16  */

17 package org.eclipse.emf.common.util;
18
19
20 import java.util.Collection JavaDoc;
21
22
23 /**
24  * A <code>BasicEList</code> that allows only {@link #isUnique unique} elements.
25  */

26 public class UniqueEList extends BasicEList
27 {
28   /**
29    * Creates an empty instance with no initial capacity.
30    */

31   public UniqueEList()
32   {
33     super();
34   }
35
36   /**
37    * Creates an empty instance with the given capacity.
38    * @param initialCapacity the initial capacity of the list before it must grow.
39    * @exception IllegalArgumentException if the <code>initialCapacity</code> is negative.
40    */

41   public UniqueEList(int initialCapacity)
42   {
43     super(initialCapacity);
44   }
45
46   /**
47    * Creates an instance that is a copy of the collection, with duplicates removed.
48    * @param collection the initial contents of the list.
49    */

50   public UniqueEList(Collection JavaDoc collection)
51   {
52     super(collection.size());
53     addAll(collection);
54   }
55
56   /**
57    * Returns <code>true</code> because this list requires uniqueness.
58    * @return <code>true</code>.
59    */

60   protected boolean isUnique()
61   {
62     return true;
63   }
64
65   /**
66    * A <code>UniqueEList</code> that {@link #useEquals uses} <code>==</code> instead of <code>equals</code> to compare members.
67    */

68   public static class FastCompare extends UniqueEList
69   {
70     /**
71      * Creates an empty instance with no initial capacity.
72      */

73     public FastCompare()
74     {
75       super();
76     }
77
78     /**
79      * Creates an empty instance with the given capacity.
80      * @param initialCapacity the initial capacity of the list before it must grow.
81      * @exception IllegalArgumentException if the <code>initialCapacity</code> is negative.
82      */

83     public FastCompare(int initialCapacity)
84     {
85       super(initialCapacity);
86     }
87
88     /**
89      * Creates an instance that is a copy of the collection, with duplicates removed.
90      * @param collection the initial contents of the list.
91      */

92     public FastCompare(Collection JavaDoc collection)
93     {
94       super(collection.size());
95       addAll(collection);
96     }
97
98     /**
99      * Returns <code>false</code> because this list uses <code>==</code>.
100      * @return <code>false</code>.
101      */

102     protected boolean useEquals()
103     {
104       return false;
105     }
106   }
107 }
108
Popular Tags