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;
 
 import java.util.Map;
 
A collection of Item's. An ItemCollection object maintains a cursor pointing to its current pages of data. Initially the cursor is positioned before the first page. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ItemCollection object, it can be used in a while loop to iterate through the collection. Network calls can be triggered when the collection is iterated across page boundaries.

Parameters:
<R> low level result type
 
 public abstract class ItemCollection<R> extends PageBasedCollection<Item, R> {
     private int totalCount;
     private int totalScannedCount;
 
     protected final void accumulateStats(ConsumedCapacity consumedCapacity,
             Integer countInteger scannedCount) {
         if (consumedCapacity != null) {
             if ( == null) {
                 // Create a new consumed capacity by cloning the one passed in
                 this. = new ConsumedCapacity();
                 .setCapacityUnits(consumedCapacity.getCapacityUnits());
                 .setGlobalSecondaryIndexes(
                     clone(consumedCapacity.getGlobalSecondaryIndexes()));
                 .setLocalSecondaryIndexes(
                     clone(consumedCapacity.getLocalSecondaryIndexes()));
                 .setTable(clone(consumedCapacity.getTable()));
                 .setTableName(consumedCapacity.getTableName());
             } else {
                 // Accumulate the capacity units 
                 final Double capunit = .getCapacityUnits();
                 final Double delta = consumedCapacity.getCapacityUnits();
                 if (capunit == null) {
                     .setCapacityUnits(delta);
                 } else {
                     .setCapacityUnits(capunit.doubleValue() 
                         + (delta == null ? 0 : delta.doubleValue()));
                 }
                 // Accumulate the GSI capacities
                 final Map<StringCapacitygsi = .getGlobalSecondaryIndexes();
                 if (gsi == null) {
                     .setGlobalSecondaryIndexes(
                         clone(consumedCapacity.getGlobalSecondaryIndexes()));
                 } else {
                     .setGlobalSecondaryIndexes(add(
                         consumedCapacity.getGlobalSecondaryIndexes(),
                         .getGlobalSecondaryIndexes()));
                 }
                 // Accumulate the LSI capacities
                 final Map<StringCapacitylsi = .getLocalSecondaryIndexes();
                 if (lsi == null) {
                     .setLocalSecondaryIndexes(
                         clone(consumedCapacity.getLocalSecondaryIndexes()));
                 } else {
                     .setLocalSecondaryIndexes(add(
                         consumedCapacity.getLocalSecondaryIndexes(),
                         .getLocalSecondaryIndexes()));
                 }
             }
         }
         if (count != null) {
             this. += count.intValue();
         }
         if (scannedCount != null) {
             this. += scannedCount.intValue();
         }
     }
 
     private Map<StringCapacityadd(Map<StringCapacityfromMap<StringCapacityto) {
         if (to == null)
             return clone(from);
         if (from != null) {
            for (Map.Entry<StringCapacityentryFrom : from.entrySet()) {
                final String key = entryFrom.getKey();
                final Capacity tocap = to.get(key);
                final Capacity fromcap = entryFrom.getValue();
                if (tocap == null) {
                    to.put(keyclone(fromcap));
                } else {
                    to.put(keynew Capacity().withCapacityUnits(
                        doubleOf(tocap) + doubleOf(fromcap)));
                }
            }
        }
        return to;
    }
    private Map<StringCapacityclone(Map<StringCapacitycapacityMap) {
        if (capacityMap == null)
            return null;
        Map<String,Capacityclone =
            new HashMap<String,Capacity>(capacityMap.size());
        for (Map.Entry<StringCapacitye : capacityMap.entrySet())
            clone.put(e.getKey(), clone(e.getValue()));
        return clone;
    }
    
    private Capacity clone(Capacity capacity) {
        return capacity == null 
             ? null
             : new Capacity().withCapacityUnits(capacity.getCapacityUnits());
    }
    
    private double doubleOf(Capacity cap) {
        if (cap == null)
            return 0.0;
        Double val = cap.getCapacityUnits();
        return val == null ? 0.0 : val.doubleValue();
    }

    
Returns the total count accumulated so far.
    public int getTotalCount() {
        return ;
    }

    
Returns the total scanned count accumulated so far.
    public int getTotalScannedCount() {
        return ;
    }

    
Returns the total consumed capacity accumulated so far.
        return ;
    }
New to GrepCode? Check out our FAQ X