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

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