Class KeyRange (5.0.3)
Stay organized with collections
Save and categorize content based on your preferences.
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.
Constructors
KeyRange(Key parent, String kind, long start, long end)
public KeyRange(Key parent, String kind, long start, long end)
Methods
equals(@Nullable Object obj)
public boolean equals(@Nullable Object obj)
Overrides
getEnd()
Returns the last Key in the range.
| Returns |
| Type |
Description |
Key |
|
getSize()
Returns the size of the range.
| Returns |
| Type |
Description |
long |
|
getStart()
Returns the first Key in the range.
| Returns |
| Type |
Description |
Key |
|
hashCode()
| Returns |
| Type |
Description |
int |
|
Overrides
iterator()
public Iterator<Key> iterator()
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-06-03 UTC.
[null,null,["Last updated 2026-06-03 UTC."],[],[]]