This project has retired. For details please refer to its
Attic page.
AbstractIterator xref
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.List;
23
24 import org.apache.chemistry.opencmis.client.runtime.util.AbstractPageFetcher.Page;
25
26
27
28
29
30
31 public abstract class AbstractIterator<T> implements Iterator<T> {
32
33 private long skipCount;
34 private int skipOffset;
35 private final AbstractPageFetcher<T> pageFetcher;
36
37 private Page<T> page;
38 private Long totalNumItems;
39 private Boolean hasMoreItems;
40
41
42
43
44
45
46
47 protected AbstractIterator(long skipCount, AbstractPageFetcher<T> pageFetcher) {
48 this.skipCount = skipCount;
49 this.pageFetcher = pageFetcher;
50 }
51
52 public long getPosition() {
53 return skipCount + skipOffset;
54 }
55
56 public long getPageNumItems() {
57 Page<T> currentPage = getCurrentPage();
58 if (currentPage != null) {
59 List<T> items = currentPage.getItems();
60 if (items != null) {
61 return items.size();
62 }
63 }
64 return 0L;
65 }
66
67 public long getTotalNumItems() {
68 if (totalNumItems == null) {
69 totalNumItems = Long.valueOf(-1);
70 Page<T> currentPage = getCurrentPage();
71 if (currentPage != null) {
72
73 if (currentPage.getTotalNumItems() != null) {
74 totalNumItems = currentPage.getTotalNumItems();
75 }
76 }
77 }
78 return totalNumItems.longValue();
79 }
80
81 public boolean getHasMoreItems() {
82 if (hasMoreItems == null) {
83 hasMoreItems = Boolean.FALSE;
84 Page<T> currentPage = getCurrentPage();
85 if (currentPage != null) {
86 if (currentPage.getHasMoreItems() != null) {
87 hasMoreItems = currentPage.getHasMoreItems();
88 }
89 }
90 }
91 return hasMoreItems.booleanValue();
92 }
93
94 public void remove() {
95 throw new UnsupportedOperationException();
96 }
97
98
99
100
101
102
103 protected long getSkipCount() {
104 return skipCount;
105 }
106
107
108
109
110
111
112 protected int getSkipOffset() {
113 return skipOffset;
114 }
115
116
117
118
119
120
121 protected int incrementSkipOffset() {
122 return skipOffset++;
123 }
124
125
126
127
128
129
130 protected Page<T> getCurrentPage() {
131 if (page == null) {
132 page = pageFetcher.fetchPage(skipCount);
133 }
134 return page;
135 }
136
137
138
139
140
141
142 protected Page<T> incrementPage() {
143 skipCount += skipOffset;
144 skipOffset = 0;
145 totalNumItems = null;
146 hasMoreItems = null;
147 page = pageFetcher.fetchPage(skipCount);
148 return page;
149 }
150
151 }