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