Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2014-2015 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.internal;

Parameters:
<T> resource type
<R> low level result type
class IteratorSupport<T,R> implements Iterator<T> {
    
Used to iterate through the resource pages, dynamically making network calls as needed.
    final PageIterator<T,R> resourcePageIterator;
    
Used to iterate through a list of resources already retrieved.
    private Iterator<T> localResourceIterator;
    private T resource;
    IteratorSupport(PageIterator<T,R> resourcePageIterator) {
        this. = resourcePageIterator;
    }
    @Override
    public boolean hasNext() {
        if ( != null) {
            return true;
        }
         = nextResource();
        return ( != null);
    }
    @Override
    public T next() {
        T rval = ;
        if (rval == null) {
            rval = nextResource();
            if (rval == null) {
                throw new NoSuchElementException("No more elements");
            }
        } else {
             = null;
        }
        return rval;
    }
    @Override
    public void remove() {
        throw new UnsupportedOperationException(
                "Collection is read-only");
    }
    private T nextResource() {
        while (true) {
            if ( != null && .hasNext()) {
                return .next();
            }
            if (!.hasNext()) {
                return null;
            }
            Page<T,R> resourcePage = .next();
             = resourcePage.iterator();
        }
    }
New to GrepCode? Check out our FAQ X