@Test public void simpleRepeatedField() { ConfigSource.Builder builder = ConfigSource.newBuilder(SomeConfig.getDefaultInstance()); builder.addValue(REPEATED_STRING_VALUE_FIELD, "a", L1); builder.addValue(REPEATED_STRING_VALUE_FIELD, "b", L2); ConfigSource source = builder.build(); SomeConfig config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getRepeatedStringValueList()).containsExactly("a", "b"); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 0)) .isEqualTo(L1); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 1)) .isEqualTo(L2); builder = source.toBuilder(); builder.addValue(REPEATED_STRING_VALUE_FIELD, "c", L3); source = builder.build(); config = (SomeConfig) source.getConfig(); Truth.assertThat(config.getRepeatedStringValueList()).containsExactly("a", "b", "c"); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 0)) .isEqualTo(L1); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 1)) .isEqualTo(L2); Truth.assertThat(source.getLocation(config, REPEATED_STRING_VALUE_FIELD.getName(), 2)) .isEqualTo(L3); }
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)); } } }
@Override public void accept(Builder nestedBuilder) { nestedBuilder.addValue(NESTED_REPEATED_INT32_VALUE_FIELD, 2, L3); } });