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