package nl.tudelft.simulation.immutablecollections; import java.util.Comparator; import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; /** * An immutable wrapper for a TreeMap. *

* 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 key type of content of this Map * @param the value type of content of this Map */ public class ImmutableTreeMap extends ImmutableAbstractMap implements ImmutableNavigableMap { /** */ private static final long serialVersionUID = 20160507L; /** * @param sortedMap the map to use for the immutable map. */ public ImmutableTreeMap(final Map sortedMap) { super(new TreeMap(sortedMap), Immutable.COPY); } /** * @param map the map to use for the immutable map. * @param copyOrWrap COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original * collection */ public ImmutableTreeMap(final NavigableMap map, final Immutable copyOrWrap) { super(copyOrWrap == Immutable.COPY ? new TreeMap(map) : map, copyOrWrap); } /** * @param immutableMap the map to use for the immutable map. */ public ImmutableTreeMap(final ImmutableAbstractMap immutableMap) { super(new TreeMap(immutableMap.getMap()), Immutable.COPY); } /** * @param immutableTreeMap the map to use for the immutable map. * @param copyOrWrap COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original * collection */ public ImmutableTreeMap(final ImmutableTreeMap immutableTreeMap, final Immutable copyOrWrap) { super(copyOrWrap == Immutable.COPY ? new TreeMap(immutableTreeMap.getMap()) : immutableTreeMap.getMap(), copyOrWrap); } /** {@inheritDoc} */ @Override protected final NavigableMap getMap() { return (NavigableMap) super.getMap(); } /** {@inheritDoc} */ @Override public final NavigableMap toMap() { return new TreeMap(super.getMap()); } /** {@inheritDoc} */ @Override public final ImmutableSortedSet keySet() { return new ImmutableTreeSet(getMap().keySet()); } /** {@inheritDoc} */ @Override public final Comparator comparator() { return getMap().comparator(); } /** {@inheritDoc} */ @Override public final ImmutableSortedMap subMap(final K fromKey, final K toKey) { return new ImmutableTreeMap(getMap().subMap(fromKey, toKey)); } /** {@inheritDoc} */ @Override public final ImmutableSortedMap headMap(final K toKey) { return new ImmutableTreeMap(getMap().headMap(toKey)); } /** {@inheritDoc} */ @Override public final ImmutableSortedMap tailMap(final K fromKey) { return new ImmutableTreeMap(getMap().tailMap(fromKey)); } /** {@inheritDoc} */ @Override public final K firstKey() { return getMap().firstKey(); } /** {@inheritDoc} */ @Override public final K lastKey() { return getMap().lastKey(); } /** {@inheritDoc} */ @Override public final K lowerKey(final K key) { return getMap().lowerKey(key); } /** {@inheritDoc} */ @Override public final K floorKey(final K key) { return getMap().floorKey(key); } /** {@inheritDoc} */ @Override public final K ceilingKey(final K key) { return getMap().ceilingKey(key); } /** {@inheritDoc} */ @Override public final K higherKey(final K key) { return getMap().higherKey(key); } /** {@inheritDoc} */ @Override public final ImmutableNavigableMap descendingMap() { return new ImmutableTreeMap(getMap().descendingMap()); } /** {@inheritDoc} */ @Override public final ImmutableNavigableMap subMap(final K fromKey, final boolean fromInclusive, final K toKey, final boolean toInclusive) { return new ImmutableTreeMap(getMap().subMap(fromKey, fromInclusive, toKey, toInclusive)); } /** {@inheritDoc} */ @Override public final ImmutableNavigableMap headMap(final K toKey, final boolean inclusive) { return new ImmutableTreeMap(getMap().headMap(toKey, inclusive)); } /** {@inheritDoc} */ @Override public final ImmutableNavigableMap tailMap(final K fromKey, final boolean inclusive) { return new ImmutableTreeMap(getMap().tailMap(fromKey, inclusive)); } /** {@inheritDoc} */ @Override public final String toString() { NavigableMap map = getMap(); if (null == map) { return "ImmutableTreeMap []"; } return "ImmutableTreeMap [" + map.toString() + "]"; } }