Class Key (2.14.1)

public final class Key extends IncompleteKey

A key that is guaranteed to be complete and could be used to reference a Google Cloud Datastore Entity. This class is immutable. See Also: Google Cloud Datastore Entities, Properties, and Keys

Inheritance

Object > BaseKey > IncompleteKey > Key

Static Methods

fromUrlSafe(String urlSafe)

public static Key fromUrlSafe(String urlSafe)

Create a Key given its URL safe encoded form.

Parameter
NameDescription
urlSafeString
Returns
TypeDescription
Key

newBuilder(IncompleteKey copyFrom, String name)

public static Key.Builder newBuilder(IncompleteKey copyFrom, String name)
Parameters
NameDescription
copyFromIncompleteKey
nameString
Returns
TypeDescription
Key.Builder

newBuilder(IncompleteKey copyFrom, long id)

public static Key.Builder newBuilder(IncompleteKey copyFrom, long id)
Parameters
NameDescription
copyFromIncompleteKey
idlong
Returns
TypeDescription
Key.Builder

newBuilder(Key copyFrom)

public static Key.Builder newBuilder(Key copyFrom)
Parameter
NameDescription
copyFromKey
Returns
TypeDescription
Key.Builder

newBuilder(Key parent, String kind, String name)

public static Key.Builder newBuilder(Key parent, String kind, String name)
Parameters
NameDescription
parentKey
kindString
nameString
Returns
TypeDescription
Key.Builder

newBuilder(Key parent, String kind, long id)

public static Key.Builder newBuilder(Key parent, String kind, long id)
Parameters
NameDescription
parentKey
kindString
idlong
Returns
TypeDescription
Key.Builder

newBuilder(String projectId, String kind, String name)

public static Key.Builder newBuilder(String projectId, String kind, String name)
Parameters
NameDescription
projectIdString
kindString
nameString
Returns
TypeDescription
Key.Builder

newBuilder(String projectId, String kind, long id)

public static Key.Builder newBuilder(String projectId, String kind, long id)
Parameters
NameDescription
projectIdString
kindString
idlong
Returns
TypeDescription
Key.Builder

Methods

getId()

public Long getId()

Returns the key's id or null if it has a name instead.

Returns
TypeDescription
Long

getName()

public String getName()

Returns the key's name or null if it has an id instead.

Returns
TypeDescription
String

getNameOrId()

public Object getNameOrId()

Returns the key's ID (as Long) or name (as String). Never null.

Returns
TypeDescription
Object

hasId()

public boolean hasId()
Returns
TypeDescription
boolean

hasName()

public boolean hasName()
Returns
TypeDescription
boolean

toUrlSafe()

public String toUrlSafe()

Returns the key in an encoded form that can be used as part of a URL.

Returns
TypeDescription
String