package nl.tudelft.simulation.immutablecollections; import java.util.Collection; import java.util.HashSet; import java.util.Set; import nl.tudelft.simulation.language.Throw; /** * An immutable wrapper for a HashSet. *

* Copyright (c) 2013-2016 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 as the immutable set. */ public ImmutableHashSet(final Collection collection) { this(collection, Immutable.COPY); } /** * @param collection the collection to use as 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 Collection collection, final Immutable copyOrWrap) { super(copyOrWrap == Immutable.COPY ? new HashSet(collection) : collection, copyOrWrap == Immutable.COPY); Throw.whenNull(copyOrWrap, "the copyOrWrap argument should be Immutable.COPY or Immutable.WRAP"); } /** * @param collection the collection to use as the immutable set. * @param copy boolean; indicates whether the immutable is a copy or a wrap */ protected ImmutableHashSet(final Collection collection, final boolean copy) { super(collection, copy); } /** * @param collection the collection to use as the immutable set. */ public ImmutableHashSet(final ImmutableCollection collection) { this(collection, Immutable.COPY); } /** * @param collection the collection to use as 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 ImmutableCollection collection, final Immutable copyOrWrap) { this(collection.toCollection(), copyOrWrap); } /** {@inheritDoc} */ @Override protected final HashSet getSet() { return (HashSet) super.getSet(); } /** {@inheritDoc} */ @Override public final Set toSet() { return new HashSet(getSet()); } /** {@inheritDoc} */ @Override @SuppressWarnings("checkstyle:designforextension") public String toString() { Set set = getSet(); if (null == set) { return "ImmutableHashSet []"; } return "ImmutableHashSet [" + set.toString() + "]"; } }