本文整理了Java中com.google.cloud.datastore.Entity.getBoolean()
方法的一些代码示例,展示了Entity.getBoolean()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.getBoolean()
方法的具体详情如下:
包路径:com.google.cloud.datastore.Entity
类名称:Entity
方法名:getBoolean
暂无
代码示例来源:origin: google/data-transfer-project
private static Map<String, Object> getProperties(Entity entity)
throws IOException, ClassNotFoundException {
if (entity == null) {
return null;
}
ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
for (String property : entity.getNames()) {
// builder.put(property, entity.getValue(property));
if (entity.getValue(property) instanceof StringValue) {
builder.put(property, (String) entity.getString(property));
} else if (entity.getValue(property) instanceof LongValue) {
// This conversion is safe because of integer to long conversion above
builder.put(property, new Long(entity.getLong(property)).intValue());
} else if (entity.getValue(property) instanceof DoubleValue) {
builder.put(property, (Double) entity.getDouble(property));
} else if (entity.getValue(property) instanceof BooleanValue) {
builder.put(property, (Boolean) entity.getBoolean(property));
} else if (entity.getValue(property) instanceof TimestampValue) {
builder.put(property, (Timestamp) entity.getTimestamp(property));
} else {
Blob blob = entity.getBlob(property);
Object obj = null;
try (ObjectInputStream in = new ObjectInputStream(blob.asInputStream())) {
obj = in.readObject();
}
builder.put(property, obj); // BlobValue
}
}
return builder.build();
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testGetArrayNoDeferredResults() {
datastore.put(ENTITY3);
Iterator<Entity> result =
datastore.fetch(KEY1, Key.newBuilder(KEY1).setName("bla").build(), KEY2, KEY3).iterator();
assertEquals(ENTITY1, result.next());
assertNull(result.next());
assertEquals(ENTITY2, result.next());
Entity entity3 = result.next();
assertEquals(ENTITY3, entity3);
assertTrue(entity3.isNull("null"));
assertFalse(entity3.getBoolean("bool"));
assertEquals(LIST_VALUE2.get(), entity3.getList("list"));
FullEntity<IncompleteKey> partial1 = entity3.getEntity("partial1");
FullEntity<IncompleteKey> partial2 = entity3.getEntity("partial2");
assertEquals(PARTIAL_ENTITY2, partial1);
assertEquals(ENTITY2, partial2);
assertEquals(ValueType.BOOLEAN, entity3.getValue("bool").getType());
assertEquals(LAT_LNG_VALUE, entity3.getValue("latLng"));
assertEquals(EMPTY_LIST_VALUE, entity3.getValue("emptyList"));
assertEquals(8, entity3.getNames().size());
assertFalse(entity3.contains("bla"));
try {
entity3.getString("str");
fail("Expecting a failure");
} catch (DatastoreException expected) {
// expected - no such property
}
assertFalse(result.hasNext());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testGetArrayNoDeferredResults() {
DATASTORE.put(ENTITY3);
Iterator<Entity> result =
DATASTORE.fetch(KEY1, Key.newBuilder(KEY1).setName("bla").build(), KEY2, KEY3).iterator();
assertEquals(ENTITY1, result.next());
assertNull(result.next());
assertEquals(ENTITY2, result.next());
Entity entity3 = result.next();
assertEquals(ENTITY3, entity3);
assertTrue(entity3.isNull("null"));
assertFalse(entity3.getBoolean("bool"));
assertEquals(LIST_VALUE2.get(), entity3.getList("list"));
FullEntity<IncompleteKey> partial1 = entity3.getEntity("partial1");
FullEntity<IncompleteKey> partial2 = entity3.getEntity("partial2");
assertEquals(PARTIAL_ENTITY2, partial1);
assertEquals(ENTITY2, partial2);
assertEquals(ValueType.BOOLEAN, entity3.getValue("bool").getType());
assertEquals(LAT_LNG_VALUE, entity3.getValue("latLng"));
assertEquals(EMPTY_LIST_VALUE, entity3.getValue("emptyList"));
assertEquals(8, entity3.getNames().size());
assertFalse(entity3.contains("bla"));
try {
entity3.getString("str");
fail("Expecting a failure");
} catch (DatastoreException expected) {
// expected - no such property
}
assertFalse(result.hasNext());
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Converts a list of task entities to a list of formatted task strings.
*
* @param tasks An iterator over task entities
* @return A list of tasks strings, one per entity
*/
static List<String> formatTasks(Iterator<Entity> tasks) {
List<String> strings = new ArrayList<>();
while (tasks.hasNext()) {
Entity task = tasks.next();
if (task.getBoolean("done")) {
strings.add(
String.format("%d : %s (done)", task.getKey().getId(), task.getString("description")));
} else {
strings.add(String.format("%d : %s (created %s)", task.getKey().getId(),
task.getString("description"), task.getTimestamp("created")));
}
}
return strings;
}
代码示例来源:origin: spotify/styx
boolean enabled(WorkflowId workflowId) throws IOException {
final Key workflowKey = workflowKey(datastore.newKeyFactory(), workflowId);
return getOpt(datastore, workflowKey)
.filter(w -> w.contains(PROPERTY_WORKFLOW_ENABLED))
.map(workflow -> workflow.getBoolean(PROPERTY_WORKFLOW_ENABLED))
.orElse(DEFAULT_WORKFLOW_ENABLED);
}
代码示例来源:origin: spotify/styx
public WorkflowState workflowState(WorkflowId workflowId) throws IOException {
final WorkflowState.Builder builder = WorkflowState.builder();
final Optional<Entity> workflowEntity = getOpt(datastore, workflowKey(datastore.newKeyFactory(), workflowId));
builder.enabled(workflowEntity.filter(w -> w.contains(PROPERTY_WORKFLOW_ENABLED))
.map(workflow -> workflow.getBoolean(PROPERTY_WORKFLOW_ENABLED))
.orElse(DEFAULT_WORKFLOW_ENABLED));
getOptInstantProperty(workflowEntity, PROPERTY_NEXT_NATURAL_TRIGGER)
.ifPresent(builder::nextNaturalTrigger);
getOptInstantProperty(workflowEntity, PROPERTY_NEXT_NATURAL_OFFSET_TRIGGER)
.ifPresent(builder::nextNaturalOffsetTrigger);
return builder.build();
}
代码示例来源:origin: org.togglz/togglz-cloud-datastore
private FeatureState createFeatureState(final Feature feature, final Entity featureEntity) {
if (featureEntity == null) {
return null;
}
final Boolean enabled = featureEntity.getBoolean(ENABLED);
final FeatureState state = new FeatureState(feature, enabled);
state.setStrategyId(getStrategyId(featureEntity));
List<Value<String>> names = valuesList(featureEntity, STRATEGY_PARAMS_NAMES);
List<Value<String>> values = valuesList(featureEntity, STRATEGY_PARAMS_VALUES);
Preconditions.checkState(names.size() == values.size());
for (int i = 0; i < names.size(); i++) {
String name = names.get(i).get();
String value = values.get(i).get();
state.setParameter(name, value);
}
return state;
}
代码示例来源:origin: spotify/styx
Set<WorkflowId> enabled() throws IOException {
final EntityQuery queryWorkflows = EntityQuery.newEntityQueryBuilder().setKind(KIND_WORKFLOW).build();
final Set<WorkflowId> enabledWorkflows = Sets.newHashSet();
datastore.query(queryWorkflows, workflow -> {
final boolean enabled =
workflow.contains(PROPERTY_WORKFLOW_ENABLED)
&& workflow.getBoolean(PROPERTY_WORKFLOW_ENABLED);
if (enabled) {
enabledWorkflows.add(parseWorkflowId(workflow));
}
});
return enabledWorkflows;
}
代码示例来源:origin: spotify/styx
static Backfill entityToBackfill(Entity entity) throws IOException {
final WorkflowId workflowId = WorkflowId.create(entity.getString(PROPERTY_COMPONENT),
entity.getString(PROPERTY_WORKFLOW));
final BackfillBuilder builder = Backfill.newBuilder()
.id(entity.getKey().getName())
.start(timestampToInstant(entity.getTimestamp(PROPERTY_START)))
.end(timestampToInstant(entity.getTimestamp(PROPERTY_END)))
.workflowId(workflowId)
.concurrency((int) entity.getLong(PROPERTY_CONCURRENCY))
.nextTrigger(timestampToInstant(entity.getTimestamp(PROPERTY_NEXT_TRIGGER)))
.schedule(Schedule.parse(entity.getString(PROPERTY_SCHEDULE)))
.allTriggered(entity.getBoolean(PROPERTY_ALL_TRIGGERED))
.halted(entity.getBoolean(PROPERTY_HALTED))
.reverse(read(entity, PROPERTY_REVERSE, Boolean.FALSE));
if (entity.contains(PROPERTY_DESCRIPTION)) {
builder.description(entity.getString(PROPERTY_DESCRIPTION));
}
if (entity.contains(PROPERTY_TRIGGER_PARAMETERS)) {
builder.triggerParameters(OBJECT_MAPPER.readValue(
entity.getString(PROPERTY_TRIGGER_PARAMETERS), TriggerParameters.class));
}
return builder.build();
}
内容来源于网络,如有侵权,请联系作者删除!