1 package org.djutils.immutablecollections;
2
3 import java.util.Collection;
4
5 import org.djutils.exceptions.Throw;
6
7 /**
8 * An abstract base class for an immutable wrapper for a Set.
9 * <p>
10 * Copyright (c) 2016-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
11 * for project information <a href="https://djutils.org" target="_blank"> https://djutils.org</a>. The DJUTILS project is
12 * distributed under a three-clause BSD-style license, which can be found at
13 * <a href="https://djutils.org/docs/license.html" target="_blank"> https://djutils.org/docs/license.html</a>.
14 * </p>
15 * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16 * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
17 * @param <E> the type of content of this Set
18 */
19 public abstract class ImmutableAbstractCollection<E> implements ImmutableCollection<E>
20 {
21 /** COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection. */
22 @SuppressWarnings("checkstyle:visibilitymodifier")
23 protected final Immutable copyOrWrap;
24
25 /**
26 * Construct an abstract immutable collection.
27 * @param copyOrWrap indicates whether the immutable is a copy or a wrap
28 */
29 public ImmutableAbstractCollection(final Immutable copyOrWrap)
30 {
31 Throw.whenNull(copyOrWrap, "the copyOrWrap argument should be Immutable.COPY or Immutable.WRAP");
32 this.copyOrWrap = copyOrWrap;
33 }
34
35 /**
36 * Returns the underlying collection of this immutable collection. In case of Immutable.WRAP, this will be the original
37 * collection. In case of IMMUTABLE.COPY, this will be the internally stored (mutable) copy of the collection.
38 * @return the underlying collection of this immutable collection.
39 */
40 protected abstract Collection<E> getUnderlyingCollection();
41 }