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) 2016-2018 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights * reserved. See for project information * https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can * be found at * https://simulation.tudelft.nl/dsol/3.0/license.html. *

* @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 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 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() + "]"; } }