Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / labs / datastore / overlay / IdAllocationPolicyInterface.java
blobcb10a8b305564cbcb189463341c73b221c369527
1 package com.google.appengine.api.labs.datastore.overlay;
3 /**
4 * An allocation policy for Datastore key IDs.
6 * Key IDs are 52 bits and are formed from a unique sequential counter value provided by the
7 * backend. The map of (counter value, ID policy) to valid IDs is one-to-one.
8 */
9 interface IdAllocationPolicyInterface {
10 /** Indicates whether {@code id} belongs to the ID range of this policy. */
11 boolean containsId(long id);
13 /** The maximum counter value that can be mapped in this policy's ID range. */
14 long getMaximumCounterValue();
16 /**
17 * Converts a counter value to an ID.
19 * @param counter the counter value to convert to an ID.
20 * @return the ID corresponding to the given counter value.
21 * @throws IllegalArgumentException if the counter is not in the range
22 * @{code [1, getMaximumCounterValue()]}.
24 long counterToId(long counter);
26 /**
27 * Converts an ID to the counter value which
28 * generated it. If the ID does not belong to the range managed by
29 * this policy.
31 * @param id the entity id to convert to a counter value.
32 * @return the counter value corresponding to the given entity id.
33 * @throws IllegalArgumentException if the ID does not belong to the range mapped by this policy.
35 long idToCounter(long id);