/** * Constructs a new empty builder, based on the given default instance for the underlying config * message. * * <p>An initialized message can also be passed, however, no source location tracking will happen * for it. */ public static Builder newBuilder(Message defaultInstance) { return new Builder( defaultInstance, defaultInstance.toBuilder(), new LinkedHashMap<MessageKey, ImmutableMap<LocationKey, Location>>()); }
/** Constructs a builder from this configuration message. */ public Builder toBuilder() { return new Builder(configMessage, configMessage.toBuilder(), new LinkedHashMap<>(locations)); }
/** Constructs a builder from this configuration message. */ public Builder toBuilder() { return new Builder(configMessage, configMessage.toBuilder(), new LinkedHashMap<>(locations)); }
Builder fieldBuilder = new Builder(currentValue, valueBuilder, locations); action.accept(fieldBuilder);
Builder fieldBuilder = new Builder(currentValue, valueBuilder, locations); action.accept(fieldBuilder);
/** * Constructs a sub-builder for given field and calls the action on it. After the action's * processing, the sub-message will be build and stored into the field of this builder. * Moreover, update locations of the sub-builder are integrated into this builder. */ public Builder withBuilder(FieldDescriptor field, BuildAction action) { // Construct a fresh builder for the given field and merge in the current value. As we depend // on message identity, we need to control this builder directly, so can't use implicit // building via getFieldBuilder. A builder created by getFieldBuilder as build() called // when the parent is called, resulting in a different message identity. Message currentValue = (Message) configBuilder.getField(field); Message.Builder protoBuilder = configBuilder.newBuilderForField(field); protoBuilder.mergeFrom(currentValue); // Construct config builder, and let the action process it. Builder fieldConfigBuilder = new Builder(currentValue, protoBuilder, locations); action.accept(fieldConfigBuilder); // Build config, which updates the location mapping, and update proto builder. ConfigSource fieldConfig = fieldConfigBuilder.build(); configBuilder.setField(field, fieldConfig.getConfig()); return this; }
/** * Constructs a sub-builder for given field and calls the action on it. After the action's * processing, the sub-message will be build and stored into the field of this builder. * Moreover, update locations of the sub-builder are integrated into this builder. */ public Builder withBuilder(FieldDescriptor field, BuildAction action) { // Construct a fresh builder for the given field and merge in the current value. As we depend // on message identity, we need to control this builder directly, so can't use implicit // building via getFieldBuilder. A builder created by getFieldBuilder as build() called // when the parent is called, resulting in a different message identity. Message currentValue = (Message) configBuilder.getField(field); Message.Builder protoBuilder = configBuilder.newBuilderForField(field); protoBuilder.mergeFrom(currentValue); // Construct config builder, and let the action process it. Builder fieldConfigBuilder = new Builder(currentValue, protoBuilder, locations); action.accept(fieldConfigBuilder); // Build config, which updates the location mapping, and update proto builder. ConfigSource fieldConfig = fieldConfigBuilder.build(); configBuilder.setField(field, fieldConfig.getConfig()); return this; }
/** * Constructs a sub-builder for a element at given index of the repeated message field, and * calls action on it. */ public Builder withBuilderAt(FieldDescriptor field, int index, BuildAction action) { Message.Builder repeatedFieldBuilder = configBuilder.newBuilderForField(field); repeatedFieldBuilder.mergeFrom((Message) configBuilder.getRepeatedField(field, index)); Builder elementBuilder = new Builder(repeatedFieldBuilder.build(), repeatedFieldBuilder, locations); action.accept(elementBuilder); // Call build so locations map is updated. ConfigSource configSource = elementBuilder.build(); // Update the list with the built element configBuilder.setRepeatedField(field, index, configSource.configMessage); return this; }
/** * Constructs a sub-builder for a element at given index of the repeated message field, and * calls action on it. */ public Builder withBuilderAt(FieldDescriptor field, int index, BuildAction action) { Message.Builder repeatedFieldBuilder = configBuilder.newBuilderForField(field); repeatedFieldBuilder.mergeFrom((Message) configBuilder.getRepeatedField(field, index)); Builder elementBuilder = new Builder(repeatedFieldBuilder.build(), repeatedFieldBuilder, locations); action.accept(elementBuilder); // Call build so locations map is updated. ConfigSource configSource = elementBuilder.build(); // Update the list with the built element configBuilder.setRepeatedField(field, index, configSource.configMessage); return this; }
/** * Constructs a sub-builder for an added element of the repeated message field, and calls action * on it. */ public Builder withAddedBuilder(FieldDescriptor field, BuildAction action) { Message.Builder repeatedFieldBuilder = configBuilder.newBuilderForField(field); Builder elementBuilder = new Builder(repeatedFieldBuilder.build(), repeatedFieldBuilder, locations); action.accept(elementBuilder); // Call build so locations map is updated. ConfigSource configSource = elementBuilder.build(); // Update the list with the built element configBuilder.addRepeatedField(field, configSource.configMessage); return this; }
/** * Constructs a sub-builder for an added element of the repeated message field, and calls action * on it. */ public Builder withAddedBuilder(FieldDescriptor field, BuildAction action) { Message.Builder repeatedFieldBuilder = configBuilder.newBuilderForField(field); Builder elementBuilder = new Builder(repeatedFieldBuilder.build(), repeatedFieldBuilder, locations); action.accept(elementBuilder); // Call build so locations map is updated. ConfigSource configSource = elementBuilder.build(); // Update the list with the built element configBuilder.addRepeatedField(field, configSource.configMessage); return this; }
/** * Constructs a new empty builder, based on the given default instance for the underlying config * message. * * <p>An initialized message can also be passed, however, no source location tracking will happen * for it. */ public static Builder newBuilder(Message defaultInstance) { return new Builder( defaultInstance, defaultInstance.toBuilder(), new LinkedHashMap<MessageKey, ImmutableMap<LocationKey, Location>>()); }