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
10
11
12
13
14
15
16
17
18
19
20
21 public class ImmutableHashSet<E> extends ImmutableAbstractSet<E>
22 {
23
24 private static final long serialVersionUID = 20160507L;
25
26
27
28
29 public ImmutableHashSet(final Collection<E> collection)
30 {
31 super(new HashSet<E>(collection));
32 }
33
34
35
36
37 public ImmutableHashSet(final ImmutableCollection<E> collection)
38 {
39 this(collection.toCollection());
40 }
41
42
43 @Override
44 protected final HashSet<E> getSet()
45 {
46 return (HashSet<E>) super.getSet();
47 }
48
49
50 @Override
51 public final Set<E> toSet()
52 {
53 return new HashSet<E>(getSet());
54 }
55
56
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 }