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 public class ImmutableLinkedHashSet<E> extends ImmutableAbstractSet<E>
21 {
22
23 private static final long serialVersionUID = 20160507L;
24
25
26
27
28 public ImmutableLinkedHashSet(final Collection<? extends E> collection)
29 {
30 super(new LinkedHashSet<E>(collection), Immutable.COPY);
31 }
32
33
34
35
36
37 public ImmutableLinkedHashSet(final Set<E> collection, final Immutable copyOrWrap)
38 {
39 super(copyOrWrap == Immutable.COPY ? new LinkedHashSet<E>(collection) : collection, copyOrWrap);
40 }
41
42
43
44
45 public ImmutableLinkedHashSet(final ImmutableAbstractCollection<? extends E> collection)
46 {
47 super(new LinkedHashSet<E>(collection.getUnderlyingCollection()), Immutable.COPY);
48 }
49
50
51
52
53
54 public ImmutableLinkedHashSet(final ImmutableAbstractSet<E> set, final Immutable copyOrWrap)
55 {
56 super(copyOrWrap == Immutable.COPY ? new LinkedHashSet<E>(set.getUnderlyingCollection())
57 : set.getUnderlyingCollection(), copyOrWrap);
58 }
59
60 @Override
61 protected Set<E> getUnderlyingCollection()
62 {
63 return super.getUnderlyingCollection();
64 }
65
66 @Override
67 public final Set<E> toSet()
68 {
69 return new LinkedHashSet<E>(getUnderlyingCollection());
70 }
71
72 @Override
73 public final String toString()
74 {
75 Set<E> set = getUnderlyingCollection();
76 if (null == set)
77 {
78 return "ImmutableLinkedHashSet []";
79 }
80 return "ImmutableLinkedHashSet [" + set.toString() + "]";
81 }
82
83 }