package nl.tudelft.simulation.immutablecollections; import java.util.Collection; import java.util.LinkedHashSet; 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 ImmutableLinkedHashSet extends ImmutableHashSet { /** */ private static final long serialVersionUID = 20160507L; /** * @param collection the collection to use as the immutable set. */ public ImmutableLinkedHashSet(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 ImmutableLinkedHashSet(final Collection collection, final Immutable copyOrWrap) { super(copyOrWrap == Immutable.COPY ? new LinkedHashSet(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. */ public ImmutableLinkedHashSet(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 ImmutableLinkedHashSet(final ImmutableCollection collection, final Immutable copyOrWrap) { this(collection.toCollection(), copyOrWrap); } /** {@inheritDoc} */ @Override public final String toString() { Set set = getSet(); if (null == set) { return "ImmutableLinkedHashSet []"; } return "ImmutableLinkedHashSet [" + set.toString() + "]"; } }