Class DynamicMessage.Builder

    • Method Detail

      • mergeFrom

        public DynamicMessage.Builder mergeFrom(Message other)
        Description copied from interface: Message.Builder
        Merge other into the message being built. other must have the exact same type as this (i.e. getDescriptorForType() == other.getDescriptorForType()). Merging occurs as follows. For each field:
        * For singular primitive fields, if the field is set in other, then other's value overwrites the value in this message.
        * For singular message fields, if the field is set in other, it is merged into the corresponding sub-message of this message using the same merging rules.
        * For repeated fields, the elements in other are concatenated with the elements in this message. This is equivalent to the Message::MergeFrom method in C++.
      • build

        public DynamicMessage build()
        Description copied from interface: MessageLite.Builder
        Constructs the message based on the state of the Builder. Subsequent changes to the Builder will not affect the returned message.
      • buildPartial

        public DynamicMessage buildPartial()
        Description copied from interface: MessageLite.Builder
        Like MessageLite.Builder.build(), but does not throw an exception if the message is missing required fields. Instead, a partial message is returned. Subsequent changes to the Builder will not affect the returned message.
      • getDefaultInstanceForType

        public DynamicMessage getDefaultInstanceForType()
        Description copied from interface: MessageLiteOrBuilder
        Get an instance of the type with no fields set. Because no fields are set, all getters for singular fields will return default values and repeated fields will appear empty. This may or may not be a singleton. This differs from the getDefaultInstance() method of generated message classes in that this method is an abstract method of the MessageLite interface whereas getDefaultInstance() is a static method of a specific class. They return the same thing.
      • getAllFields

        public Map<Descriptors.FieldDescriptor,Object> getAllFields()
        Description copied from interface: MessageOrBuilder
        Returns a collection of all the fields in this message which are set and their corresponding values. A singular ("required" or "optional") field is set iff hasField() returns true for that field. A "repeated" field is set iff getRepeatedFieldCount() is greater than zero. The values are exactly what would be returned by calling MessageOrBuilder.getField(Descriptors.FieldDescriptor) for each field. The map is guaranteed to be a sorted map, so iterating over it will return fields in order by field number.
        If this is for a builder, the returned map may or may not reflect future changes to the builder. Either way, the returned map is itself unmodifiable.
      • newBuilderForField

        public DynamicMessage.Builder newBuilderForField(Descriptors.FieldDescriptor field)
        Description copied from interface: Message.Builder
        Create a Builder for messages of the appropriate type for the given field. Messages built with this can then be passed to setField(), setRepeatedField(), or addRepeatedField().
      • hasField

        public boolean hasField(Descriptors.FieldDescriptor field)
        Description copied from interface: MessageOrBuilder
        Returns true if the given field is set. This is exactly equivalent to calling the generated "has" accessor method corresponding to the field.
      • getField

        public Object getField(Descriptors.FieldDescriptor field)
        Description copied from interface: MessageOrBuilder
        Obtains the value of the given field, or the default value if it is not set. For primitive fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the value is returned. For embedded message fields, the sub-message is returned. For repeated fields, a java.util.List is returned.
      • getRepeatedFieldCount

        public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
        Description copied from interface: MessageOrBuilder
        Gets the number of elements of a repeated field. This is exactly equivalent to calling the generated "Count" accessor method corresponding to the field.
      • getRepeatedField

        public Object getRepeatedField(Descriptors.FieldDescriptor field,
                                       int index)
        Description copied from interface: MessageOrBuilder
        Gets an element of a repeated field. For primitive fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the value is returned. For embedded message fields, the sub-message is returned.
      • getFieldBuilder

        public Message.Builder getFieldBuilder(Descriptors.FieldDescriptor field)
        Description copied from interface: Message.Builder
        Get a nested builder instance for the given field.

        Normally, we hold a reference to the immutable message object for the message type field. Some implementations(the generated message builders), however, can also hold a reference to the builder object (a nested builder) for the field.

        If the field is already backed up by a nested builder, the nested builder will be returned. Otherwise, a new field builder will be created and returned. The original message field (if exist) will be merged into the field builder, which will then be nested into its parent builder.

        NOTE: implementations that do not support nested builders will throw UnsupportedException.