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