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

com.amazonaws.services.dynamodbv2.document.Page Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Amazon DynamoDB module holds the client classes that are used for communicating with Amazon DynamoDB Service

The newest version!
/*
 * Copyright 2014-2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file 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 com.amazonaws.services.dynamodbv2.document;

import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

import com.amazonaws.AmazonServiceException;

/**
 * A page contains a list of items; accessing methods on the list are
 * guaranteed to be purely in-memory operations that will not block or throw
 * exceptions because of transient network issues. A page also knows whether it
 * has a "next page", and if so knows how to retrieve it (which
 * will almost certainly involve a remote network call that may block or
 * fail).
 *
 * @param  item type
 * @param  low level result type
 */
public abstract class Page implements Iterable {
    private final List content;
    private final R lowLevelResult;

    /**
     * Checks whether this page has a "next page." If this method returns
     * true, the next page can be retrieved by calling {@code next}. If it
     * returns false, any call to {@code next} will be guaranteed to throw an
     * {@code IllegalStateException}.
     *
     * @return true if there is next page; false otherwise
     */
    public abstract boolean hasNextPage();

    /**
     * Retrieves the next page.
     *
     * @return the next page
     * @throws NoSuchElementException if there is no next page
     * @throws AmazonServiceException on error making the remote call
     */
    public abstract Page nextPage();

    /**
     * @param content an unmodifiable list of content
     * @param lowLevelResult the low level (response) result from AWSS
     */
    public Page(List content, R lowLevelResult) {
        if (content == null || lowLevelResult == null)
            throw new IllegalArgumentException("both content and lowLevelResult must be specified");
        this.content = content;
        this.lowLevelResult = lowLevelResult;
    }

    public final int size() {
        return content.size();
    }

    @Override
    public final Iterator iterator() {
        return content.iterator();
    }

    @Override
    public String toString() {
        return content.toString();
    }

    public final R getLowLevelResult() {
        return lowLevelResult;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy