1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.client.runtime.util;
20
21 import java.util.Iterator;
22 import java.util.NoSuchElementException;
23
24 import org.apache.chemistry.opencmis.client.api.ItemIterable;
25
26
27
28
29 public class EmptyItemIterable<T> implements ItemIterable<T> {
30
31 public static final EmptyItemIterable<?> INSTANCE = new EmptyItemIterable<Object>();
32
33 @SuppressWarnings("unchecked")
34 public static <U> EmptyItemIterable<U> instance() {
35 return (EmptyItemIterable<U>) INSTANCE;
36 }
37
38 @Override
39 public ItemIterable<T> skipTo(long position) {
40 if (position != 0) {
41 throw new IllegalArgumentException(String.valueOf(position));
42 }
43 return this;
44 }
45
46 @Override
47 public ItemIterable<T> getPage() {
48 return this;
49 }
50
51 @Override
52 public ItemIterable<T> getPage(int maxNumItems) {
53 return this;
54 }
55
56 @Override
57 @SuppressWarnings("unchecked")
58 public Iterator<T> iterator() {
59 return (Iterator<T>) EmptyIterator.INSTANCE;
60 }
61
62 @Override
63 public long getPageNumItems() {
64 return 0;
65 }
66
67 @Override
68 public boolean getHasMoreItems() {
69 return false;
70 }
71
72 @Override
73 public long getTotalNumItems() {
74 return 0;
75 }
76
77
78
79
80 public static class EmptyIterator<V> implements Iterator<V> {
81 public static final Iterator<?> INSTANCE = new EmptyIterator<Object>();
82
83 @Override
84 public boolean hasNext() {
85 return false;
86 }
87
88 @Override
89 public V next() {
90 throw new NoSuchElementException();
91 }
92
93 @Override
94 public void remove() {
95 throw new UnsupportedOperationException();
96 }
97 }
98
99 }