Debian Codegraph @

net/sf/saxon/ma/parray/ImmList0.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.ma.parray;
9
10 import java.util.Collections;
11 import java.util.Iterator;
12
13 /**
14 * Implementation of an immutable empty list
15 * @param <E> the (nominal) type of the list elements
16 */
17
18 public class ImmList0<E> extends ImmList<E> {
19
20 final static ImmList0 INSTANCE = new ImmList0();
21
22 private ImmList0() {}
23
24 @Override
25 public E get(int index) {
26 throw outOfBounds(index, 0);
27 }
28
29 @Override
30 public int size() {
31 return 0;
32 }
33
34 @Override
35 public boolean isEmpty() {
36 return true;
37 }
38
39 @Override
40 public ImmList<E> replace(int index, E member) {
41 throw outOfBounds(index, 0);
42 }
43
44 @Override
45 public ImmList<E> insert(int index, E member) {
46 if (index == 0) {
47 return new ImmList1<>(member);
48 } else {
49 throw outOfBounds(index, 0);
50 }
51 }
52
53 @Override
54 public ImmList<E> append(E member) {
55 return new ImmList1<>(member);
56 }
57
58 @Override
59 public ImmList<E> appendList(ImmList<E> members) {
60 return members;
61 }
62
63 @Override
64 public ImmList<E> remove(int index) {
65 throw outOfBounds(index, 0);
66 }
67
68 @Override
69 public ImmList<E> subList(int start, int end) {
70 if (start == 0 && end == 0) {
71 return this;
72 } else {
73 throw outOfBounds(0, 0);
74 }
75 }
76
77 @Override
78 public Iterator<E> iterator() {
79 return Collections.emptyIterator();
80 }
81 }
82