1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.commons.util.list;
22
23 import java.io.Serializable;
24
25 import org.millscript.commons.alert.alerts.Fault;
26 import org.millscript.commons.util.IList;
27 import org.millscript.commons.util.ListIterator;
28 import org.millscript.commons.util.iterator.NullListIterator;
29
30 /**
31 * This class provides an immutable empty <code>List</code> implementation.
32 */
33 public class IEmptyList< V > extends AbstractIList< V > implements Cloneable, Serializable {
34
35 /**
36 * This is the ID from the release 0.1.0 for future compatibility.
37 */
38 private static final long serialVersionUID = 4150759314269848376L;
39
40 /**
41 * The immutable empty list. This is provided for convenience within your
42 * applications, where an immutable empty list is required.
43 */
44 public static final IList EMPTY_LIST = new IEmptyList();
45
46 /**
47 * @see java.lang.Object#clone()
48 */
49 @Override
50 public Object clone() throws CloneNotSupportedException {
51
52 return super.clone();
53 }
54
55 /**
56 * @see org.millscript.commons.util.list.AbstractIList#doGet(int)
57 */
58 @Override
59 protected V doGet( final int pos ) {
60 throw new Fault(
61 "An empty list has no elements to index!"
62 ).culprit( "index", pos ).decorate( this ).mishap();
63 }
64
65 /**
66 * @see org.millscript.commons.util.list.AbstractIList#doSlice(int, int, boolean)
67 */
68 @Override
69 protected IList< V > doSlice( final int first, final int last, final boolean share ) {
70
71
72
73 throw new Fault(
74 "Cannot make a non-zero length slice of an empty list"
75 ).culprit(
76 "first index",
77 first
78 ).culprit(
79 "last index",
80 last
81 ).decorate( this ).mishap();
82 }
83
84 /**
85 * @see org.millscript.commons.util.IList#indexOf(java.lang.Object)
86 */
87 public int indexOf( final V value ) {
88 return 0;
89 }
90
91 /**
92 * @see org.millscript.commons.util.IMap#iterator(boolean)
93 */
94 @SuppressWarnings( "unchecked" )
95 public ListIterator< V > iterator( final boolean share ) {
96
97 return new NullListIterator();
98 }
99
100 /**
101 * @see org.millscript.commons.util.IMap#size()
102 */
103 public int size() {
104 return 0;
105 }
106
107 }