setValue(field, key, configMessage.configMessage, null); return this;
setValue(field, key, configMessage.configMessage, null); return this;
@Test public void mapField() { ConfigSource.Builder builder = ConfigSource.newBuilder(SomeConfig.getDefaultInstance()); builder.setValue(MAP_VALUE_FIELD, "X", "A", L1); builder.setValue(MAP_VALUE_FIELD, "Y", "B", L2); ConfigSource source = builder.build(); SomeConfig config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getMapValue().get("X")).isEqualTo("A"); Truth.assertThat(config.getMapValue().get("Y")).isEqualTo("B"); Truth.assertThat(source.getLocation(config, MAP_VALUE_FIELD.getName(), "X")).isEqualTo(L1); Truth.assertThat(source.getLocation(config, MAP_VALUE_FIELD.getName(), "Y")).isEqualTo(L2); }
.setValue( Service.getDescriptor().findFieldByNumber(Service.CONFIG_VERSION_FIELD_NUMBER), null,
@Test public void mergeTest() { ConfigSource.Builder builder = ConfigSource.newBuilder(SomeConfig.getDefaultInstance()); builder.setValue(STRING_VALUE_FIELD, null, "A", L1); builder.withBuilder( NESTED_CONFIG_FIELD, builder.setValue(STRING_VALUE_FIELD, null, "", L2); builder.withBuilder( NESTED_CONFIG_FIELD,
Object valueObj = NodeConverterUtils.convert(helper, valueField, entry.getValueNode()); if (valueObj != null) { builder.setValue(field, keyObj, valueObj, helper.getLocation(entry.getValueNode()));
Object valueObj = NodeConverterUtils.convert(helper, valueField, entry.getValueNode()); if (valueObj != null) { builder.setValue(field, keyObj, valueObj, helper.getLocation(entry.getValueNode()));
@Test public void nestedSimpleField() { ConfigSource.Builder builder = ConfigSource.newBuilder(SomeConfig.getDefaultInstance()); builder.setValue(STRING_VALUE_FIELD, null, "Hello World", L1); builder.withBuilder( NESTED_CONFIG_FIELD, null, new BuildAction() { @Override public void accept(ConfigSource.Builder subBuilder) { subBuilder.setValue(NESTED_STRING_VALUE_FIELD, null, "Sub World", L2); } }); ConfigSource source = builder.build(); SomeConfig config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getStringValue()).isEqualTo("Hello World"); Truth.assertThat(source.getLocation(config, STRING_VALUE_FIELD.getName(), null)).isEqualTo(L1); Truth.assertThat(config.getNestedConfig().getNestedStringValue()).isEqualTo("Sub World"); Truth.assertThat( source.getLocation(config.getNestedConfig(), NESTED_STRING_VALUE_FIELD.getName(), null)) .isEqualTo(L2); }
private void handleNonMessageField(ConfigSource.Builder builder, FieldDescriptor field, Node value){ if (field.isRepeated()) { SequenceNode list = NodeConverterUtils.expectList(helper, field, value); for (Node elem : list.getValue()) { Object protoValue = NodeConverterUtils.convert(helper, field, elem); if (protoValue != null) { builder.addValue(field, protoValue, helper.getLocation(elem)); } } addExplicitLocationField(builder, field, value); } else { Object protoValue = NodeConverterUtils.convert(helper, field, value); if (protoValue != null) { builder.setValue(field, null, protoValue, helper.getLocation(value)); } } }
private void handleNonMessageField(ConfigSource.Builder builder, FieldDescriptor field, Node value){ if (field.isRepeated()) { SequenceNode list = NodeConverterUtils.expectList(helper, field, value); for (Node elem : list.getValue()) { Object protoValue = NodeConverterUtils.convert(helper, field, elem); if (protoValue != null) { builder.addValue(field, protoValue, helper.getLocation(elem)); } } addExplicitLocationField(builder, field, value); } else { Object protoValue = NodeConverterUtils.convert(helper, field, value); if (protoValue != null) { builder.setValue(field, null, protoValue, helper.getLocation(value)); } } }
@Test public void simpleField() { ConfigSource.Builder builder = ConfigSource.newBuilder(SomeConfig.getDefaultInstance()); builder.setValue(STRING_VALUE_FIELD, null, "Hello World", L1); ConfigSource source = builder.build(); SomeConfig config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getStringValue()).isEqualTo("Hello World"); Truth.assertThat(source.getLocation(config, STRING_VALUE_FIELD.getName(), null)).isEqualTo(L1); builder = source.toBuilder(); builder.setValue(STRING_VALUE_FIELD, null, "", L2); source = builder.build(); config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getStringValue()).isEqualTo(""); Truth.assertThat(source.getLocation(config, STRING_VALUE_FIELD.getName(), null)).isEqualTo(L2); }
@Override public void accept(ConfigSource.Builder subBuilder) { subBuilder.setValue(NESTED_STRING_VALUE_FIELD, null, "B", L1); } });
@Override public void accept(ConfigSource.Builder subBuilder) { subBuilder.setValue(NESTED_STRING_VALUE_FIELD, null, "A", L1); } });
@Override public void accept(ConfigSource.Builder subBuilder) { subBuilder.setValue(NESTED_STRING_VALUE_FIELD, null, "B", L2); } });
@Override public void accept(ConfigSource.Builder subBuilder) { subBuilder.setValue(NESTED_STRING_VALUE_FIELD, null, "Sub World", L2); } });
@Override public void accept(ConfigSource.Builder subBuilder) { subBuilder.setValue(NESTED_STRING_VALUE_FIELD, null, "C", L2); } });