1 package org.djutils.immutablecollections;
2
3 import java.util.Collection;
4 import java.util.HashSet;
5 import java.util.Set;
6
7
8
9
10
11
12
13
14
15
16
17
18
19 public class ImmutableHashSet<E> extends ImmutableAbstractSet<E>
20 {
21
22 private static final long serialVersionUID = 20160507L;
23
24
25
26
27
28 public ImmutableHashSet(final Collection<? extends E> collection)
29 {
30 super(new HashSet<E>(collection), Immutable.COPY);
31 }
32
33
34
35
36
37
38 public ImmutableHashSet(final Set<E> set, final Immutable copyOrWrap)
39 {
40 super(copyOrWrap == Immutable.COPY ? new HashSet<E>(set) : set, copyOrWrap);
41 }
42
43
44
45
46
47 public ImmutableHashSet(final ImmutableAbstractCollection<? extends E> collection)
48 {
49 super(new HashSet<E>(collection.getUnderlyingCollection()), Immutable.COPY);
50 }
51
52
53
54
55
56
57 public ImmutableHashSet(final ImmutableAbstractSet<E> set, final Immutable copyOrWrap)
58 {
59 super(copyOrWrap == Immutable.COPY ? new HashSet<E>(set.getUnderlyingCollection()) : set.getUnderlyingCollection(),
60 copyOrWrap);
61 }
62
63 @Override
64 protected Set<E> getUnderlyingCollection()
65 {
66 return super.getUnderlyingCollection();
67 }
68
69 @Override
70 public final Set<E> toSet()
71 {
72 return new HashSet<E>(getUnderlyingCollection());
73 }
74
75 @Override
76 @SuppressWarnings("checkstyle:designforextension")
77 public String toString()
78 {
79 Set<E> set = getUnderlyingCollection();
80 if (null == set)
81 {
82 return "ImmutableHashSet []";
83 }
84 return "ImmutableHashSet [" + set.toString() + "]";
85 }
86
87 }