@CheckForNull public static ProtobufSystemInfo.Attribute attribute(Section section, String key) { for (ProtobufSystemInfo.Attribute attribute : section.getAttributesList()) { if (attribute.getKey().equals(key)) { return attribute; } } return null; }
@Test public void export_system_info() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThat(section.getName()).isEqualTo("Compute Engine Database Connection"); assertThat(section.getAttributesCount()).isEqualTo(9); assertThat(section.getAttributes(0).getKey()).isEqualTo("Pool Initial Size"); assertThat(section.getAttributes(0).getLongValue()).isGreaterThanOrEqualTo(0); }
private void writeAttribute(ProtobufSystemInfo.Attribute attribute, JsonWriter json) { switch (attribute.getValueCase()) { case BOOLEAN_VALUE: json.prop(attribute.getKey(), attribute.getBooleanValue()); break; case LONG_VALUE: json.prop(attribute.getKey(), attribute.getLongValue()); break; case DOUBLE_VALUE: json.prop(attribute.getKey(), attribute.getDoubleValue()); break; case STRING_VALUE: json.prop(attribute.getKey(), attribute.getStringValue()); break; case VALUE_NOT_SET: json.name(attribute.getKey()).beginArray().values(attribute.getStringValuesList()).endArray(); break; default: throw new IllegalArgumentException("Unsupported type: " + attribute.getValueCase()); } }
private void writeAttribute(ProtobufSystemInfo.Attribute attribute, JsonWriter json) { switch (attribute.getValueCase()) { case BOOLEAN_VALUE: json.prop(attribute.getKey(), attribute.getBooleanValue()); break; case LONG_VALUE: json.prop(attribute.getKey(), attribute.getLongValue()); break; case DOUBLE_VALUE: json.prop(attribute.getKey(), attribute.getDoubleValue()); break; case STRING_VALUE: json.prop(attribute.getKey(), attribute.getStringValue()); break; case VALUE_NOT_SET: json.name(attribute.getKey()).beginArray().values(attribute.getStringValuesList()).endArray(); break; default: throw new IllegalArgumentException("Unsupported type: " + attribute.getValueCase()); } }