package nl.tudelft.simulation.immutablecollections; import java.util.Collection; import java.util.Comparator; import java.util.NavigableSet; import java.util.TreeSet; /** * An immutable wrapper for a TreeSet. *

* 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 ImmutableTreeSet extends ImmutableAbstractSet implements ImmutableNavigableSet { /** */ private static final long serialVersionUID = 20160507L; /** * @param sortedSet the collection to use for the immutable set. */ public ImmutableTreeSet(final Collection sortedSet) { super(new TreeSet(sortedSet), Immutable.COPY); } /** * @param treeSet 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 ImmutableTreeSet(final NavigableSet treeSet, final Immutable copyOrWrap) { super(copyOrWrap == Immutable.COPY ? new TreeSet(treeSet) : treeSet, copyOrWrap); } /** * @param immutableSortedSet the collection to use for the immutable set. */ public ImmutableTreeSet(final ImmutableAbstractSet immutableSortedSet) { super(new TreeSet(immutableSortedSet.getCollection()), Immutable.COPY); } /** * @param immutableTreeSet 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 ImmutableTreeSet(final ImmutableTreeSet immutableTreeSet, final Immutable copyOrWrap) { super(copyOrWrap == Immutable.COPY ? new TreeSet(immutableTreeSet.getCollection()) : immutableTreeSet.getCollection(), copyOrWrap); } /** {@inheritDoc} */ @Override public final NavigableSet toSet() { return new TreeSet(getCollection()); } /** {@inheritDoc} */ @Override protected NavigableSet getCollection() { return (NavigableSet) super.getCollection(); } /** {@inheritDoc} */ @Override public final Comparator comparator() { return getCollection().comparator(); } /** {@inheritDoc} */ @Override public final ImmutableSortedSet subSet(final E fromElement, final E toElement) { return new ImmutableTreeSet(getCollection().subSet(fromElement, toElement)); } /** {@inheritDoc} */ @Override public final ImmutableSortedSet headSet(final E toElement) { return new ImmutableTreeSet(getCollection().headSet(toElement)); } /** {@inheritDoc} */ @Override public final ImmutableSortedSet tailSet(final E fromElement) { return new ImmutableTreeSet(getCollection().tailSet(fromElement)); } /** {@inheritDoc} */ @Override public final E first() { return getCollection().first(); } /** {@inheritDoc} */ @Override public final E last() { return getCollection().last(); } /** {@inheritDoc} */ @Override public final E lower(final E e) { return getCollection().lower(e); } /** {@inheritDoc} */ @Override public final E floor(final E e) { return getCollection().floor(e); } /** {@inheritDoc} */ @Override public final E ceiling(final E e) { return getCollection().ceiling(e); } /** {@inheritDoc} */ @Override public final E higher(final E e) { return getCollection().higher(e); } /** {@inheritDoc} */ @Override public final ImmutableNavigableSet descendingSet() { return new ImmutableTreeSet(getCollection().descendingSet()); } /** {@inheritDoc} */ @Override public final ImmutableIterator descendingIterator() { return new ImmutableIterator(getCollection().descendingIterator()); } /** {@inheritDoc} */ @Override public final ImmutableNavigableSet subSet(final E fromElement, final boolean fromInclusive, final E toElement, final boolean toInclusive) { return new ImmutableTreeSet(getCollection().subSet(fromElement, fromInclusive, toElement, toInclusive)); } /** {@inheritDoc} */ @Override public final ImmutableNavigableSet headSet(final E toElement, final boolean inclusive) { return new ImmutableTreeSet(getCollection().headSet(toElement, inclusive)); } /** {@inheritDoc} */ @Override public final ImmutableNavigableSet tailSet(final E fromElement, final boolean inclusive) { return new ImmutableTreeSet(getCollection().tailSet(fromElement, inclusive)); } /** {@inheritDoc} */ @Override public final String toString() { NavigableSet set = getCollection(); if (null == set) { return "ImmutableTreeSet []"; } return "ImmutableTreeSet [" + set.toString() + "]"; } }