All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.chemistry.opencmis.client.runtime.util.AbstractIterable Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.chemistry.opencmis.client.runtime.util;

import org.apache.chemistry.opencmis.client.api.ItemIterable;

/**
 * Abstract ItemIterable implementation.
 *
 * @param  the type returned by the iterable's iterator
 */
public abstract class AbstractIterable implements ItemIterable {

    private final AbstractPageFetcher pageFetcher;
    private final long skipCount;
    private AbstractIterator iterator;

    protected AbstractIterable(AbstractPageFetcher pageFetcher) {
        this(0, pageFetcher);
    }

    protected AbstractIterable(long position, AbstractPageFetcher pageFetcher) {
        this.pageFetcher = pageFetcher;
        this.skipCount = position;
    }

    /**
     * Gets the skip count
     *
     * @return  skip count
     */
    protected long getSkipCount() {
        return skipCount;
    }

    /**
     * Gets the page fetcher
     *
     * @return  page fetcher
     */
    protected AbstractPageFetcher getPageFetcher() {
        return pageFetcher;
    }

    /**
     * Construct the iterator
     *
     * @return  iterator
     */
    protected abstract AbstractIterator createIterator();

    @Override
    public AbstractIterator iterator() {
        return getIterator();
    }

    @Override
    public ItemIterable skipTo(long position) {
        return new CollectionIterable(position, pageFetcher);
    }

    @Override
    public ItemIterable getPage() {
        return new CollectionPageIterable(skipCount, pageFetcher);
    }

    @Override
    public ItemIterable getPage(int maxNumItems) {
        this.pageFetcher.setMaxNumItems(maxNumItems);
        return new CollectionPageIterable(skipCount, pageFetcher);
    }

    @Override
    public long getPageNumItems() {
        return getIterator().getPageNumItems();
    }

    @Override
    public boolean getHasMoreItems() {
        return getIterator().getHasMoreItems();
    }

    @Override
    public long getTotalNumItems() {
        return getIterator().getTotalNumItems();
    }

    private AbstractIterator getIterator() {
        if (this.iterator == null) {
            this.iterator = createIterator();
        }
        return this.iterator;
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy