Class KeyRange (2.0.0)

public final class KeyRange implements Iterable<Key>, Serializable

Represents a range of unique datastore identifiers from getStart().getId() to getEnd().getId() inclusive. If an instance of this class is the result of a call to DatastoreService.allocateIds(), the Keys returned by this instance have been consumed in the datastore's id-space and are guaranteed never to be reused.
This class can be used to construct Entities with Keys that have specific id values without fear of the datastore creating new records with those same ids at a later date. This can be helpful as part of a data migration or large bulk upload where you may need to preserve existing ids and relationships between entities.
This class is threadsafe but the Iterators returned by #iterator() are not.

Inheritance

java.lang.Object > KeyRange

Constructors

KeyRange(Key parent, String kind, long start, long end)

public KeyRange(Key parent, String kind, long start, long end)
Parameters
Name Description
parent Key
kind String
start long
end long

Methods

equals(@Nullable Object obj)

public boolean equals(@Nullable Object obj)
Parameter
Name Description
obj @org.checkerframework.checker.nullness.qual.Nullable java.lang.Object
Returns
Type Description
boolean
Overrides

getEnd()

public Key getEnd()

Returns the last Key in the range.

Returns
Type Description
Key

getSize()

public long getSize()

Returns the size of the range.

Returns
Type Description
long

getStart()

public Key getStart()

Returns the first Key in the range.

Returns
Type Description
Key

hashCode()

public int hashCode()
Returns
Type Description
int
Overrides

iterator()

public Iterator<Key> iterator()
Returns
Type Description
Iterator<Key>