This project has retired. For details please refer to its
Attic page.
AbstractIterable xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.client.runtime.util;
2021import org.apache.chemistry.opencmis.client.api.ItemIterable;
2223/**24 * Abstract <code>ItemIterable</code> implementation.25 *26 * @param <T> the type returned by the iterable's iterator27 */28publicabstractclass AbstractIterable<T> implements ItemIterable<T> {
2930privatefinal AbstractPageFetcher<T> pageFetcher;
31privatefinallong skipCount;
32private AbstractIterator<T> iterator;
3334protectedAbstractIterable(AbstractPageFetcher<T> pageFetcher) {
35this(0, pageFetcher);
36 }
3738protectedAbstractIterable(long position, AbstractPageFetcher<T> pageFetcher) {
39this.pageFetcher = pageFetcher;
40this.skipCount = position;
41 }
4243/**44 * Gets the skip count45 *46 * @return skip count47 */48protectedlong getSkipCount() {
49return skipCount;
50 }
5152/**53 * Gets the page fetcher54 *55 * @return page fetcher56 */57protected AbstractPageFetcher<T> getPageFetcher() {
58return pageFetcher;
59 }
6061/**62 * Construct the iterator63 *64 * @return iterator65 */66protectedabstract AbstractIterator<T> createIterator();
6768public AbstractIterator<T> iterator() {
69return getIterator();
70 }
7172public ItemIterable<T> skipTo(long position) {
73returnnew CollectionIterable<T>(position, pageFetcher);
74 }
7576public ItemIterable<T> getPage() {
77returnnew CollectionPageIterable<T>(skipCount, pageFetcher);
78 }
7980public ItemIterable<T> getPage(int maxNumItems) {
81this.pageFetcher.setMaxNumItems(maxNumItems);
82returnnew CollectionPageIterable<T>(skipCount, pageFetcher);
83 }
8485publiclong getPageNumItems() {
86return getIterator().getPageNumItems();
87 }
8889publicboolean getHasMoreItems() {
90return getIterator().getHasMoreItems();
91 }
9293publiclong getTotalNumItems() {
94return getIterator().getTotalNumItems();
95 }
9697private AbstractIterator<T> getIterator() {
98if (this.iterator == null) {
99this.iterator = createIterator();
100 }
101returnthis.iterator;
102 }
103 }
104