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