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