View Javadoc
1   package org.opentrafficsim.core.immutablecollections;
2   
3   import java.util.Collection;
4   import java.util.EnumSet;
5   import java.util.HashSet;
6   import java.util.Set;
7   
8   /**
9    * An immutable wrapper for a HashSet.
10   * <p>
11   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
13   * </p>
14   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
15   * initial version May 7, 2016 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
18   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
19   * @param <E> the type of content of this Set
20   */
21  public class ImmutableHashSet<E> extends ImmutableAbstractSet<E>
22  {
23      /** */
24      private static final long serialVersionUID = 20160507L;
25  
26      /**
27       * @param collection the set to use as the immutable set.
28       */
29      public ImmutableHashSet(final Collection<E> collection)
30      {
31          super(new HashSet<E>(collection));
32      }
33  
34      /**
35       * @param collection the set to use as the immutable set.
36       */
37      public ImmutableHashSet(final ImmutableCollection<E> collection)
38      {
39          this(collection.toCollection());
40      }
41  
42      /** {@inheritDoc} */
43      @Override
44      protected final HashSet<E> getSet()
45      {
46          return (HashSet<E>) super.getSet();
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      public final Set<E> toSet()
52      {
53          return new HashSet<E>(getSet());
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public final String toString()
59      {
60          Set<E> set = getSet();
61          if (null == set)
62          {
63              return "ImmutableHashSet []";
64          }
65          return "ImmutableHashSet [" + set.toString() + "]";
66      }
67  
68  }