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

* Copyright (c) 2016-2018 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights * reserved. See for project information * https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can * be found at * https://simulation.tudelft.nl/dsol/3.0/license.html. *

* $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 collection the collection to use for the immutable list. */ public ImmutableArrayList(final Collection collection) { super(new ArrayList(collection), Immutable.COPY); } /** * @param list the list to use for 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); } /** * @param collection the collection to use for the immutable list. */ public ImmutableArrayList(final ImmutableAbstractCollection collection) { super(new ArrayList(collection.getCollection()), Immutable.COPY); } /** * @param list the list to use for 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 ImmutableAbstractList list, final Immutable copyOrWrap) { super(copyOrWrap == Immutable.COPY ? new ArrayList(list.getCollection()) : list.getCollection(), copyOrWrap); } /** {@inheritDoc} */ @Override public final ArrayList toList() { return new ArrayList(getCollection()); } /** {@inheritDoc} */ @Override protected List getCollection() { return super.getCollection(); } /** {@inheritDoc} */ @Override public final ImmutableList subList(final int fromIndex, final int toIndex) { return new ImmutableArrayList<>(getCollection().subList(fromIndex, toIndex)); } /** {@inheritDoc} */ @Override public final String toString() { List list = getCollection(); if (null == list) { return "ImmutableArrayList []"; } return "ImmutableArrayList [" + list.toString() + "]"; } }