com.google.protobuf
Class GeneratedMessage.Builder<BuilderType extends GeneratedMessage.Builder>

java.lang.Object
  extended by com.google.protobuf.AbstractMessage.Builder<BuilderType>
      extended by com.google.protobuf.GeneratedMessage.Builder<BuilderType>
All Implemented Interfaces:
Message.Builder, java.lang.Cloneable
Direct Known Subclasses:
DescriptorProtos.DescriptorProto.Builder, DescriptorProtos.DescriptorProto.ExtensionRange.Builder, DescriptorProtos.EnumDescriptorProto.Builder, DescriptorProtos.EnumValueDescriptorProto.Builder, DescriptorProtos.FieldDescriptorProto.Builder, DescriptorProtos.FileDescriptorProto.Builder, DescriptorProtos.FileDescriptorSet.Builder, DescriptorProtos.MethodDescriptorProto.Builder, DescriptorProtos.ServiceDescriptorProto.Builder, DescriptorProtos.UninterpretedOption.Builder, DescriptorProtos.UninterpretedOption.NamePart.Builder, GeneratedMessage.ExtendableBuilder
Enclosing class:
GeneratedMessage

public abstract static class GeneratedMessage.Builder<BuilderType extends GeneratedMessage.Builder>
extends AbstractMessage.Builder<BuilderType>


Constructor Summary
protected GeneratedMessage.Builder()
           
 
Method Summary
protected
<T> void
addAll(java.lang.Iterable<T> values, java.util.Collection<? super T> list)
          Adds the values to the list.
 BuilderType addRepeatedField(Descriptors.FieldDescriptor field, java.lang.Object value)
          Like setRepeatedField, but appends the value as a new element.
 BuilderType clearField(Descriptors.FieldDescriptor field)
          Clears the field.
 java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> getAllFields()
          Like Message.getAllFields().
 Descriptors.Descriptor getDescriptorForType()
          Get the message's type's descriptor.
 java.lang.Object getField(Descriptors.FieldDescriptor field)
          Like Message.getField(Descriptors.FieldDescriptor)
 java.lang.Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
          Like Message.getRepeatedField(Descriptors.FieldDescriptor,int)
 int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
          Like Message.getRepeatedFieldCount(Descriptors.FieldDescriptor)
 UnknownFieldSet getUnknownFields()
          Get the UnknownFieldSet for this message.
 boolean hasField(Descriptors.FieldDescriptor field)
          Like Message.hasField(Descriptors.FieldDescriptor)
protected abstract  GeneratedMessage internalGetResult()
          Get the message being built.
 boolean isInitialized()
          Returns true if all required fields in the message and all embedded messages are set, false otherwise.
 BuilderType mergeFrom(Message other)
          Merge other into the message being built.
 BuilderType mergeUnknownFields(UnknownFieldSet unknownFields)
          Merge some unknown fields into the UnknownFieldSet for this message.
 Message.Builder newBuilderForField(Descriptors.FieldDescriptor field)
          Create a Builder for messages of the appropriate type for the given field.
protected  boolean parseUnknownField(CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistry extensionRegistry, int tag)
          Called by subclasses to parse an unknown field.
 BuilderType setField(Descriptors.FieldDescriptor field, java.lang.Object value)
          Sets a field to the given value.
 BuilderType setRepeatedField(Descriptors.FieldDescriptor field, int index, java.lang.Object value)
          Sets an element of a repeated field to the given value.
 BuilderType setUnknownFields(UnknownFieldSet unknownFields)
          Set the UnknownFieldSet for this message.
 
Methods inherited from class com.google.protobuf.AbstractMessage.Builder
clear, clone, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.google.protobuf.Message.Builder
build, buildPartial, getDefaultInstanceForType
 

Constructor Detail

GeneratedMessage.Builder

protected GeneratedMessage.Builder()
Method Detail

internalGetResult

protected abstract GeneratedMessage internalGetResult()
Get the message being built. We don't just pass this to the constructor because it becomes null when build() is called.


mergeFrom

public BuilderType 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++.

Specified by:
mergeFrom in interface Message.Builder
Overrides:
mergeFrom in class AbstractMessage.Builder<BuilderType extends GeneratedMessage.Builder>

getDescriptorForType

public Descriptors.Descriptor getDescriptorForType()
Description copied from interface: Message.Builder
Get the message's type's descriptor. See Message.getDescriptorForType().


getAllFields

public java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> getAllFields()
Description copied from interface: Message.Builder
Like Message.getAllFields(). The returned map may or may not reflect future changes to the builder. Either way, the returned map is itself unmodifiable.


newBuilderForField

public Message.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: Message.Builder
Like Message.hasField(Descriptors.FieldDescriptor)


getField

public java.lang.Object getField(Descriptors.FieldDescriptor field)
Description copied from interface: Message.Builder
Like Message.getField(Descriptors.FieldDescriptor)


setField

public BuilderType setField(Descriptors.FieldDescriptor field,
                            java.lang.Object value)
Description copied from interface: Message.Builder
Sets a field to the given value. The value must be of the correct type for this field, i.e. the same type that Message.getField(Descriptors.FieldDescriptor) would return.


clearField

public BuilderType clearField(Descriptors.FieldDescriptor field)
Description copied from interface: Message.Builder
Clears the field. This is exactly equivalent to calling the generated "clear" accessor method corresponding to the field.


getRepeatedFieldCount

public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Description copied from interface: Message.Builder
Like Message.getRepeatedFieldCount(Descriptors.FieldDescriptor)


getRepeatedField

public java.lang.Object getRepeatedField(Descriptors.FieldDescriptor field,
                                         int index)
Description copied from interface: Message.Builder
Like Message.getRepeatedField(Descriptors.FieldDescriptor,int)


setRepeatedField

public BuilderType setRepeatedField(Descriptors.FieldDescriptor field,
                                    int index,
                                    java.lang.Object value)
Description copied from interface: Message.Builder
Sets an element of a repeated field to the given value. The value must be of the correct type for this field, i.e. the same type that Message.getRepeatedField(Descriptors.FieldDescriptor,int) would return.


addRepeatedField

public BuilderType addRepeatedField(Descriptors.FieldDescriptor field,
                                    java.lang.Object value)
Description copied from interface: Message.Builder
Like setRepeatedField, but appends the value as a new element.


getUnknownFields

public final UnknownFieldSet getUnknownFields()
Description copied from interface: Message.Builder
Get the UnknownFieldSet for this message.


setUnknownFields

public final BuilderType setUnknownFields(UnknownFieldSet unknownFields)
Description copied from interface: Message.Builder
Set the UnknownFieldSet for this message.


mergeUnknownFields

public final BuilderType mergeUnknownFields(UnknownFieldSet unknownFields)
Description copied from interface: Message.Builder
Merge some unknown fields into the UnknownFieldSet for this message.

Specified by:
mergeUnknownFields in interface Message.Builder
Overrides:
mergeUnknownFields in class AbstractMessage.Builder<BuilderType extends GeneratedMessage.Builder>

isInitialized

public boolean isInitialized()
Description copied from interface: Message.Builder
Returns true if all required fields in the message and all embedded messages are set, false otherwise.


parseUnknownField

protected boolean parseUnknownField(CodedInputStream input,
                                    UnknownFieldSet.Builder unknownFields,
                                    ExtensionRegistry extensionRegistry,
                                    int tag)
                             throws java.io.IOException
Called by subclasses to parse an unknown field.

Returns:
true unless the tag is an end-group tag.
Throws:
java.io.IOException

addAll

protected <T> void addAll(java.lang.Iterable<T> values,
                          java.util.Collection<? super T> list)
Adds the values to the list.

Throws:
java.lang.NullPointerException - if any of the elements of values is null.


Copyright © 2008-2009. All Rights Reserved.