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