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-2024 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 /** */ 22 private static final long serialVersionUID = 20180908L; 23 24 /** COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection. */ 25 @SuppressWarnings("checkstyle:visibilitymodifier") 26 protected final Immutable copyOrWrap; 27 28 /** 29 * Construct an abstract immutable collection. 30 * @param copyOrWrap Immutable; indicates whether the immutable is a copy or a wrap 31 */ 32 public ImmutableAbstractCollection(final Immutable copyOrWrap) 33 { 34 Throw.whenNull(copyOrWrap, "the copyOrWrap argument should be Immutable.COPY or Immutable.WRAP"); 35 this.copyOrWrap = copyOrWrap; 36 } 37 38 /** 39 * Returns the underlying collection of this immutable collection. In case of Immutable.WRAP, this will be the original 40 * collection. In case of IMMUTABLE.COPY, this will be the internally stored (mutable) copy of the collection. 41 * @return the underlying collection of this immutable collection. 42 */ 43 protected abstract Collection<E> getUnderlyingCollection(); 44 }