Java Code Examples for com.google.datastore.v1.Value#getValueTypeCase()

The following examples show how to use com.google.datastore.v1.Value#getValueTypeCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
/**
 * @return the double contained in value
 * @throws IllegalArgumentException if the value does not contain a double.
 */
public static double getDouble(Value value) {
  if (value.getValueTypeCase() != ValueTypeCase.DOUBLE_VALUE) {
    throw new IllegalArgumentException("Value does not contain a double.");
  }
  return value.getDoubleValue();
}
 
Example 2
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
/**
 * @return the key contained in value
 * @throws IllegalArgumentException if the value does not contain a key.
 */
public static Key getKey(Value value) {
  if (value.getValueTypeCase() != ValueTypeCase.KEY_VALUE) {
    throw new IllegalArgumentException("Value does not contain a key.");
  }
  return value.getKeyValue();
}
 
Example 3
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
/**
 * @return the blob contained in value
 * @throws IllegalArgumentException if the value does not contain a blob.
 */
public static ByteString getByteString(Value value) {
  if (value.getMeaning() == 18 && value.getValueTypeCase() == ValueTypeCase.STRING_VALUE) {
    return value.getStringValueBytes();
  } else if (value.getValueTypeCase() == ValueTypeCase.BLOB_VALUE) {
    return value.getBlobValue();
  }
  throw new IllegalArgumentException("Value does not contain a blob.");
}
 
Example 4
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
/**
 * @return the entity contained in value
 * @throws IllegalArgumentException if the value does not contain an entity.
 */
public static Entity getEntity(Value value) {
  if (value.getValueTypeCase() != ValueTypeCase.ENTITY_VALUE) {
    throw new IllegalArgumentException("Value does not contain an Entity.");
  }
  return value.getEntityValue();
}
 
Example 5
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
/**
 * @return the string contained in value
 * @throws IllegalArgumentException if the value does not contain a string.
 */
public static String getString(Value value) {
  if (value.getValueTypeCase() != ValueTypeCase.STRING_VALUE) {
    throw new IllegalArgumentException("Value does not contain a string.");
  }
  return value.getStringValue();
}
 
Example 6
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
/**
 * @return the boolean contained in value
 * @throws IllegalArgumentException if the value does not contain a boolean.
 */
public static boolean getBoolean(Value value) {
  if (value.getValueTypeCase() != ValueTypeCase.BOOLEAN_VALUE) {
    throw new IllegalArgumentException("Value does not contain a boolean.");
  }
  return value.getBooleanValue();
}
 
Example 7
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
/**
 * @return the long contained in value
 * @throws IllegalArgumentException if the value does not contain a long.
 */
public static long getLong(Value value) {
  if (value.getValueTypeCase() != ValueTypeCase.INTEGER_VALUE) {
    throw new IllegalArgumentException("Value does not contain an integer.");
  }
  return value.getIntegerValue();
}
 
Example 8
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
/**
 * @return the timestamp in microseconds contained in value
 * @throws IllegalArgumentException if the value does not contain a timestamp.
 */
public static long getTimestamp(Value value) {
  if (value.getMeaning() == 18 && value.getValueTypeCase() == ValueTypeCase.INTEGER_VALUE) {
    return value.getIntegerValue();
  } else if (value.getValueTypeCase() == ValueTypeCase.TIMESTAMP_VALUE) {
    return toMicroseconds(value.getTimestampValue());
  }
  throw new IllegalArgumentException("Value does not contain a timestamp.");
}
 
Example 9
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
/**
 * @return the array contained in value as a list.
 * @throws IllegalArgumentException if the value does not contain an array.
 */
public static List<Value> getList(Value value) {
  if (value.getValueTypeCase() != ValueTypeCase.ARRAY_VALUE) {
    throw new IllegalArgumentException("Value does not contain an array.");
  }
  return value.getArrayValue().getValuesList();
}