package nl.tudelft.simulation.immutablecollections;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* An immutable wrapper for a HashSet.
*
* Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights
* reserved.
* BSD-style license. See DSOL License.
*
* $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck
* $, initial version May 7, 2016
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param the type of content of this Set
*/
public class ImmutableHashSet extends ImmutableAbstractSet
{
/** */
private static final long serialVersionUID = 20160507L;
/**
* @param collection the collection to use for the immutable set.
*/
public ImmutableHashSet(final Collection extends E> collection)
{
super(new HashSet(collection), Immutable.COPY);
}
/**
* @param set the set to use for the immutable set.
* @param copyOrWrap COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original
* collection
*/
public ImmutableHashSet(final Set set, final Immutable copyOrWrap)
{
super(copyOrWrap == Immutable.COPY ? new HashSet(set) : set, copyOrWrap);
}
/**
* @param collection the collection to use for the immutable set.
*/
public ImmutableHashSet(final ImmutableAbstractCollection extends E> collection)
{
super(new HashSet(collection.getCollection()), Immutable.COPY);
}
/**
* @param set the set to use for the immutable set.
* @param copyOrWrap COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original
* collection
*/
public ImmutableHashSet(final ImmutableAbstractSet set, final Immutable copyOrWrap)
{
super(copyOrWrap == Immutable.COPY ? new HashSet(set.getCollection()) : set.getCollection(), copyOrWrap);
}
/** {@inheritDoc} */
@Override
protected Set getCollection()
{
return super.getCollection();
}
/** {@inheritDoc} */
@Override
public final Set toSet()
{
return new HashSet(getCollection());
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("checkstyle:designforextension")
public String toString()
{
Set set = getCollection();
if (null == set)
{
return "ImmutableHashSet []";
}
return "ImmutableHashSet [" + set.toString() + "]";
}
}