org.eclipse.emf.common.util.UniqueEList Maven / Gradle / Ivy
The newest version!
/**
* Copyright (c) 2002-2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
*/
package org.eclipse.emf.common.util;
import java.util.Collection;
/**
* A BasicEList
that allows only {@link #isUnique unique} elements.
*/
public class UniqueEList extends BasicEList
{
private static final long serialVersionUID = 1L;
/**
* Creates an empty instance with no initial capacity.
*/
public UniqueEList()
{
super();
}
/**
* Creates an empty instance with the given capacity.
* @param initialCapacity the initial capacity of the list before it must grow.
* @exception IllegalArgumentException if the initialCapacity
is negative.
*/
public UniqueEList(int initialCapacity)
{
super(initialCapacity);
}
/**
* Creates an instance that is a copy of the collection, with duplicates removed.
* @param collection the initial contents of the list.
*/
public UniqueEList(Collection extends E> collection)
{
super(collection.size());
addAll(collection);
}
/**
* Returns true
because this list requires uniqueness.
* @return true
.
*/
@Override
protected boolean isUnique()
{
return true;
}
/**
* A UniqueEList
that {@link #useEquals uses} ==
instead of equals
to compare members.
*/
public static class FastCompare extends UniqueEList
{
private static final long serialVersionUID = 1L;
/**
* Creates an empty instance with no initial capacity.
*/
public FastCompare()
{
super();
}
/**
* Creates an empty instance with the given capacity.
* @param initialCapacity the initial capacity of the list before it must grow.
* @exception IllegalArgumentException if the initialCapacity
is negative.
*/
public FastCompare(int initialCapacity)
{
super(initialCapacity);
}
/**
* Creates an instance that is a copy of the collection, with duplicates removed.
* @param collection the initial contents of the list.
*/
public FastCompare(Collection extends E> collection)
{
super(collection.size());
addAll(collection);
}
/**
* Returns false
because this list uses ==
.
* @return false
.
*/
@Override
protected boolean useEquals()
{
return false;
}
}
}