package nl.tudelft.simulation.immutablecollections; import java.util.ArrayList; import java.util.List; import nl.tudelft.simulation.language.Throw; /** * An immutable wrapper for an ArrayList. *

* 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 List */ public class ImmutableArrayList extends ImmutableAbstractList { /** */ private static final long serialVersionUID = 20160507L; /** * @param list the list to use as the immutable list. */ public ImmutableArrayList(final List list) { this(list, Immutable.COPY); } /** * @param list the list to use as the immutable list. * @param copyOrWrap COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection */ public ImmutableArrayList(final List list, final Immutable copyOrWrap) { super(copyOrWrap == Immutable.COPY ? new ArrayList(list) : list, copyOrWrap == Immutable.COPY); Throw.whenNull(copyOrWrap, "the copyOrWrap argument should be Immutable.COPY or Immutable.WRAP"); } /** * @param list the list to use as the immutable list. */ public ImmutableArrayList(final ImmutableList list) { this(list, Immutable.COPY); } /** * @param list the list to use as the immutable list. * @param copyOrWrap COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection */ public ImmutableArrayList(final ImmutableList list, final Immutable copyOrWrap) { this(((ImmutableAbstractList) list).getList(), copyOrWrap); } /** {@inheritDoc} */ @Override protected final ArrayList getList() { return (ArrayList) super.getList(); } /** {@inheritDoc} */ @Override public final List toList() { return new ArrayList(getList()); } /** {@inheritDoc} */ @Override public final ImmutableList subList(final int fromIndex, final int toIndex) { return new ImmutableArrayList<>(getList().subList(fromIndex, toIndex)); } /** {@inheritDoc} */ @Override public final String toString() { List list = getList(); if (null == list) { return "ImmutableArrayList []"; } return "ImmutableArrayList [" + list.toString() + "]"; } }