49
49
* @author kenton@google.com Kenton Varda
51
public interface Message extends MessageLite {
53
* Get the message's type's descriptor. This differs from the
54
* {@code getDescriptor()} method of generated message classes in that
55
* this method is an abstract method of the {@code Message} interface
56
* whereas {@code getDescriptor()} is a static method of a specific class.
57
* They return the same thing.
59
Descriptors.Descriptor getDescriptorForType();
61
// (From MessageLite, re-declared here only for return type covariance.)
62
Message getDefaultInstanceForType();
65
* Returns a collection of all the fields in this message which are set
66
* and their corresponding values. A singular ("required" or "optional")
67
* field is set iff hasField() returns true for that field. A "repeated"
68
* field is set iff getRepeatedFieldSize() is greater than zero. The
69
* values are exactly what would be returned by calling
70
* {@link #getField(Descriptors.FieldDescriptor)} for each field. The map
71
* is guaranteed to be a sorted map, so iterating over it will return fields
72
* in order by field number.
74
Map<Descriptors.FieldDescriptor, Object> getAllFields();
77
* Returns true if the given field is set. This is exactly equivalent to
78
* calling the generated "has" accessor method corresponding to the field.
79
* @throws IllegalArgumentException The field is a repeated field, or
80
* {@code field.getContainingType() != getDescriptorForType()}.
82
boolean hasField(Descriptors.FieldDescriptor field);
85
* Obtains the value of the given field, or the default value if it is
86
* not set. For primitive fields, the boxed primitive value is returned.
87
* For enum fields, the EnumValueDescriptor for the value is returend. For
88
* embedded message fields, the sub-message is returned. For repeated
89
* fields, a java.util.List is returned.
91
Object getField(Descriptors.FieldDescriptor field);
94
* Gets the number of elements of a repeated field. This is exactly
95
* equivalent to calling the generated "Count" accessor method corresponding
97
* @throws IllegalArgumentException The field is not a repeated field, or
98
* {@code field.getContainingType() != getDescriptorForType()}.
100
int getRepeatedFieldCount(Descriptors.FieldDescriptor field);
103
* Gets an element of a repeated field. For primitive fields, the boxed
104
* primitive value is returned. For enum fields, the EnumValueDescriptor
105
* for the value is returend. For embedded message fields, the sub-message
107
* @throws IllegalArgumentException The field is not a repeated field, or
108
* {@code field.getContainingType() != getDescriptorForType()}.
110
Object getRepeatedField(Descriptors.FieldDescriptor field, int index);
112
/** Get the {@link UnknownFieldSet} for this message. */
113
UnknownFieldSet getUnknownFields();
51
public interface Message extends MessageLite, MessageOrBuilder {
115
53
// -----------------------------------------------------------------
116
54
// Comparison and hashing
131
70
* Returns the hash code value for this message. The hash code of a message
132
* is defined to be <tt>getDescriptor().hashCode() ^ map.hashCode()</tt>,
133
* where <tt>map</tt> is a map of field numbers to field values.
71
* should mix the message's type (object identity of the decsriptor) with its
72
* contents (known and unknown field values). Subclasses must implement this;
73
* inheriting {@code Object.hashCode()} is incorrect.
135
75
* @return the hash code value for this message
136
76
* @see Map#hashCode()
198
138
Descriptors.Descriptor getDescriptorForType();
200
// (From MessageLite.Builder, re-declared here only for return type
202
Message getDefaultInstanceForType();
205
* Like {@link Message#getAllFields()}. The returned map may or may not
206
* reflect future changes to the builder. Either way, the returned map is
207
* itself unmodifiable.
209
Map<Descriptors.FieldDescriptor, Object> getAllFields();
212
141
* Create a Builder for messages of the appropriate type for the given
213
142
* field. Messages built with this can then be passed to setField(),
235
158
Builder clearField(Descriptors.FieldDescriptor field);
238
* Like {@link Message#getRepeatedFieldCount(Descriptors.FieldDescriptor)}
240
int getRepeatedFieldCount(Descriptors.FieldDescriptor field);
243
* Like {@link Message#getRepeatedField(Descriptors.FieldDescriptor,int)}
245
Object getRepeatedField(Descriptors.FieldDescriptor field, int index);
248
161
* Sets an element of a repeated field to the given value. The value must
249
162
* be of the correct type for this field, i.e. the same type that
250
163
* {@link Message#getRepeatedField(Descriptors.FieldDescriptor,int)} would