com.google.protobuf.Struct.getFieldsMap()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中com.google.protobuf.Struct.getFieldsMap()方法的一些代码示例,展示了Struct.getFieldsMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Struct.getFieldsMap()方法的具体详情如下:
包路径:com.google.protobuf.Struct
类名称:Struct
方法名:getFieldsMap

Struct.getFieldsMap介绍

[英]```
Unordered map of dynamically typed values.

`map<string, .google.protobuf.Value> fields = 1;`
[中]```
Unordered map of dynamically typed values.

map<string, .google.protobuf.Value> fields = 1;

代码示例

代码示例来源:origin: com.google.protobuf/protobuf-java

/**
 * Use {@link #getFieldsMap()} instead.
 */
@java.lang.Deprecated
public java.util.Map<java.lang.String, com.google.protobuf.Value> getFields() {
 return getFieldsMap();
}
/**

代码示例来源:origin: googleapis/google-cloud-java

@Override
 public int size() {
  return struct.getFieldsMap().size();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public Iterator<Entry<String, Object>> iterator() {
 return Iterators.transform(struct.getFieldsMap().entrySet().iterator(), VALUE_TO_OBJECT);
}

代码示例来源:origin: googleapis/google-cloud-java

private void checkStructField(Struct struct, String key, Value expected) {
 Map<String, Value> map = struct.getFieldsMap();
 checkMapField(map, key, expected);
}

代码示例来源:origin: Netflix/conductor

Struct struct = any.getStructValue();
Map<String, Object> map = new HashMap<>();
for (Map.Entry<String, Value> pair : struct.getFieldsMap().entrySet()) {
  map.put(pair.getKey(), fromProto(pair.getValue()));

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testNewStructEmpty() {
 Struct struct = Structs.newStruct(EMPTY_MAP);
 assertTrue(struct.getFieldsMap().isEmpty());
}

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

/**
 * Lists contexts
 *
 * @param sessionId Identifier of the DetectIntent session.
 * @param projectId Project/Agent Id.
 * @return List of Contexts found.
 */
public static List<Context> listContexts(String sessionId, String projectId) throws Exception {
 List<Context> contexts = Lists.newArrayList();
 // Instantiates a client
 try (ContextsClient contextsClient = ContextsClient.create()) {
  // Set the session name using the sessionId (UUID) and projectId (my-project-id)
  SessionName session = SessionName.of(projectId, sessionId);
  // Performs the list contexts request
  for (Context context : contextsClient.listContexts(session).iterateAll()) {
   System.out.format("Context name: %s\n", context.getName());
   System.out.format("Lifespan Count: %d\n", context.getLifespanCount());
   System.out.format("Fields:\n");
   for (Entry<String, Value> entry : context.getParameters().getFieldsMap().entrySet()) {
    if (entry.getValue().hasStructValue()) {
     System.out.format("\t%s: %s\n", entry.getKey(), entry.getValue());
    }
   }
   contexts.add(context);
  }
 }
 return contexts;
}
// [END dialogflow_list_contexts]

代码示例来源:origin: com.google.cloud/google-cloud-logging

@Override
 public int size() {
  return struct.getFieldsMap().size();
 }
}

代码示例来源:origin: yeriomin/play-store-api

/**
 * Use {@link #getFieldsMap()} instead.
 */
@java.lang.Deprecated
public java.util.Map<java.lang.String, com.google.protobuf.Value> getFields() {
 return getFieldsMap();
}
/**

代码示例来源:origin: yeriomin/play-store-api

/**
 * <pre>
 * Unordered map of dynamically typed values.
 * </pre>
 *
 * <code>map&lt;string, .google.protobuf.Value&gt; fields = 1;</code>
 */
public java.util.Map<java.lang.String, com.google.protobuf.Value> getFieldsMap() {
 return java.util.Collections.unmodifiableMap(
   instance.getFieldsMap());
}
/**

代码示例来源:origin: yeriomin/play-store-api

public int getFieldsCount() {
 return instance.getFieldsMap().size();
}
/**

代码示例来源:origin: yeriomin/play-store-api

/**
 * <pre>
 * Unordered map of dynamically typed values.
 * </pre>
 *
 * <code>map&lt;string, .google.protobuf.Value&gt; fields = 1;</code>
 */
public boolean containsFields(
  java.lang.String key) {
 if (key == null) { throw new java.lang.NullPointerException(); }
 return instance.getFieldsMap().containsKey(key);
}

代码示例来源:origin: com.google.cloud/google-cloud-logging

@Override
public Iterator<Entry<String, Object>> iterator() {
 return Iterators.transform(struct.getFieldsMap().entrySet().iterator(), VALUE_TO_OBJECT);
}

代码示例来源:origin: yeriomin/play-store-api

/**
 * <pre>
 * Unordered map of dynamically typed values.
 * </pre>
 *
 * <code>map&lt;string, .google.protobuf.Value&gt; fields = 1;</code>
 */
public com.google.protobuf.Value getFieldsOrDefault(
  java.lang.String key,
  com.google.protobuf.Value defaultValue) {
 if (key == null) { throw new java.lang.NullPointerException(); }
 java.util.Map<java.lang.String, com.google.protobuf.Value> map =
   instance.getFieldsMap();
 return map.containsKey(key) ? map.get(key) : defaultValue;
}
/**

代码示例来源:origin: yeriomin/play-store-api

/**
 * <pre>
 * Unordered map of dynamically typed values.
 * </pre>
 *
 * <code>map&lt;string, .google.protobuf.Value&gt; fields = 1;</code>
 */
public com.google.protobuf.Value getFieldsOrThrow(
  java.lang.String key) {
 if (key == null) { throw new java.lang.NullPointerException(); }
 java.util.Map<java.lang.String, com.google.protobuf.Value> map =
   instance.getFieldsMap();
 if (!map.containsKey(key)) {
  throw new java.lang.IllegalArgumentException();
 }
 return map.get(key);
}
/**

代码示例来源:origin: Clarifai/clarifai-java

public static JsonObject structToJsonObject(Struct metadata) {
 JsonObject jsonObject = new JsonObject();
 for (Map.Entry<String, Value> entry : metadata.getFieldsMap().entrySet()) {
  jsonObject.add(entry.getKey(), valueToJsonElement(entry.getValue()));
 }
 return jsonObject;
}

代码示例来源:origin: com.hubspot.jackson/jackson-datatype-protobuf

@Test
public void itSetsEmptyMapWhenStructIsEmpty() throws IOException {
 String json = "{\"struct\":{}}";
 HasStruct valueWrapper = camelCase().readValue(json, HasStruct.class);
 assertThat(valueWrapper.hasStruct()).isTrue();
 assertThat(valueWrapper.getStruct().getFieldsMap()).isEmpty();
}

代码示例来源:origin: com.hubspot.jackson/jackson-datatype-protobuf

@Test
 public void itReadsAllStructValueTypes() throws IOException {
  String json = "{\"struct\":{\"null\":null,\"number\":1.5,\"string\":\"test\",\"boolean\":true,\"struct\":{\"key\":\"nested\"},\"list\":[\"nested\"]}}";
  HasStruct message = camelCase().readValue(json, HasStruct.class);
  assertThat(message.hasStruct()).isTrue();

  Map<String, Value> map = message.getStruct().getFieldsMap();
  Value nested = Value.newBuilder().setStringValue("nested").build();
  Struct nestedStruct = Struct.newBuilder().putFields("key", nested).build();
  ListValue list = ListValue.newBuilder().addValues(nested).build();

  assertThat(map.size()).isEqualTo(6);
  assertThat(map.get("null")).isEqualTo(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build());
  assertThat(map.get("number")).isEqualTo(Value.newBuilder().setNumberValue(1.5).build());
  assertThat(map.get("string")).isEqualTo(Value.newBuilder().setStringValue("test").build());
  assertThat(map.get("boolean")).isEqualTo(Value.newBuilder().setBoolValue(true).build());
  assertThat(map.get("struct")).isEqualTo(Value.newBuilder().setStructValue(nestedStruct).build());
  assertThat(map.get("list")).isEqualTo(Value.newBuilder().setListValue(list).build());
 }
}

代码示例来源:origin: com.hubspot.jackson/jackson-datatype-protobuf

@Test
public void itReadsMixedStruct() throws IOException {
 String json = "{\"value\":{\"null\":null,\"number\":1.5,\"string\":\"test\",\"boolean\":true,\"struct\":{\"key\":\"nested\"},\"list\":[\"nested\"]}}";
 HasValue message = camelCase().readValue(json, HasValue.class);
 assertThat(message.hasValue()).isTrue();
 Value value = message.getValue();
 switch (value.getKindCase()) {
  case STRUCT_VALUE:
   Map<String, Value> map = value.getStructValue().getFieldsMap();
   Value nested = Value.newBuilder().setStringValue("nested").build();
   Struct nestedStruct = Struct.newBuilder().putFields("key", nested).build();
   ListValue list = ListValue.newBuilder().addValues(nested).build();
   assertThat(map.size()).isEqualTo(6);
   assertThat(map.get("null")).isEqualTo(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build());
   assertThat(map.get("number")).isEqualTo(Value.newBuilder().setNumberValue(1.5).build());
   assertThat(map.get("string")).isEqualTo(Value.newBuilder().setStringValue("test").build());
   assertThat(map.get("boolean")).isEqualTo(Value.newBuilder().setBoolValue(true).build());
   assertThat(map.get("struct")).isEqualTo(Value.newBuilder().setStructValue(nestedStruct).build());
   assertThat(map.get("list")).isEqualTo(Value.newBuilder().setListValue(list).build());
   break;
  default:
   fail("Unexpected value kind: " + value.getKindCase());
 }
}

代码示例来源:origin: com.hubspot.jackson/jackson-datatype-protobuf

@Test
public void itReadsStructValue() throws IOException {
 String json = "{\"value\":{\"key\":\"value\"}}";
 HasValue valueWrapper = camelCase().readValue(json, HasValue.class);
 assertThat(valueWrapper.hasValue()).isTrue();
 Value value = valueWrapper.getValue();
 switch (value.getKindCase()) {
  case STRUCT_VALUE:
   Entry<String, Value> entry = entry("key", Value.newBuilder().setStringValue("value").build());
   assertThat(value.getStructValue().getFieldsMap()).containsExactly(entry);
   break;
  default:
   fail("Unexpected value kind: " + value.getKindCase());
 }
}

相关文章