~verterok/ubuntu/lucid/protobuf/2.4.0a-backport

« back to all changes in this revision

Viewing changes to java/src/main/java/com/google/protobuf/Message.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-05-31 14:41:47 UTC
  • mfrom: (2.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110531144147-s41g5fozgvyo462l
Tags: 2.4.0a-2ubuntu1
* Merge with Debian; remaining changes:
  - Fix linking with -lpthread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 *
49
49
 * @author kenton@google.com Kenton Varda
50
50
 */
51
 
public interface Message extends MessageLite {
52
 
  /**
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.
58
 
   */
59
 
  Descriptors.Descriptor getDescriptorForType();
60
 
 
61
 
  // (From MessageLite, re-declared here only for return type covariance.)
62
 
  Message getDefaultInstanceForType();
63
 
 
64
 
  /**
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.
73
 
   */
74
 
  Map<Descriptors.FieldDescriptor, Object> getAllFields();
75
 
 
76
 
  /**
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()}.
81
 
   */
82
 
  boolean hasField(Descriptors.FieldDescriptor field);
83
 
 
84
 
  /**
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.
90
 
   */
91
 
  Object getField(Descriptors.FieldDescriptor field);
92
 
 
93
 
  /**
94
 
   * Gets the number of elements of a repeated field.  This is exactly
95
 
   * equivalent to calling the generated "Count" accessor method corresponding
96
 
   * to the field.
97
 
   * @throws IllegalArgumentException The field is not a repeated field, or
98
 
   *           {@code field.getContainingType() != getDescriptorForType()}.
99
 
   */
100
 
  int getRepeatedFieldCount(Descriptors.FieldDescriptor field);
101
 
 
102
 
  /**
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
106
 
   * is returned.
107
 
   * @throws IllegalArgumentException The field is not a repeated field, or
108
 
   *           {@code field.getContainingType() != getDescriptorForType()}.
109
 
   */
110
 
  Object getRepeatedField(Descriptors.FieldDescriptor field, int index);
111
 
 
112
 
  /** Get the {@link UnknownFieldSet} for this message. */
113
 
  UnknownFieldSet getUnknownFields();
 
51
public interface Message extends MessageLite, MessageOrBuilder {
114
52
 
115
53
  // -----------------------------------------------------------------
116
54
  // Comparison and hashing
119
57
   * Compares the specified object with this message for equality.  Returns
120
58
   * <tt>true</tt> if the given object is a message of the same type (as
121
59
   * defined by {@code getDescriptorForType()}) and has identical values for
122
 
   * all of its fields.
 
60
   * all of its fields.  Subclasses must implement this; inheriting
 
61
   * {@code Object.equals()} is incorrect.
123
62
   *
124
63
   * @param other object to be compared for equality with this message
125
64
   * @return <tt>true</tt> if the specified object is equal to this message
129
68
 
130
69
  /**
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.
134
74
   *
135
75
   * @return the hash code value for this message
136
76
   * @see Map#hashCode()
158
98
  /**
159
99
   * Abstract interface implemented by Protocol Message builders.
160
100
   */
161
 
  interface Builder extends MessageLite.Builder {
 
101
  interface Builder extends MessageLite.Builder, MessageOrBuilder {
162
102
    // (From MessageLite.Builder, re-declared here only for return type
163
103
    // covariance.)
164
104
    Builder clear();
197
137
     */
198
138
    Descriptors.Descriptor getDescriptorForType();
199
139
 
200
 
    // (From MessageLite.Builder, re-declared here only for return type
201
 
    // covariance.)
202
 
    Message getDefaultInstanceForType();
203
 
 
204
 
    /**
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.
208
 
     */
209
 
    Map<Descriptors.FieldDescriptor, Object> getAllFields();
210
 
 
211
140
    /**
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(),
215
144
     */
216
145
    Builder newBuilderForField(Descriptors.FieldDescriptor field);
217
146
 
218
 
    /** Like {@link Message#hasField(Descriptors.FieldDescriptor)} */
219
 
    boolean hasField(Descriptors.FieldDescriptor field);
220
 
 
221
 
    /** Like {@link Message#getField(Descriptors.FieldDescriptor)} */
222
 
    Object getField(Descriptors.FieldDescriptor field);
223
 
 
224
147
    /**
225
148
     * Sets a field to the given value.  The value must be of the correct type
226
149
     * for this field, i.e. the same type that
235
158
    Builder clearField(Descriptors.FieldDescriptor field);
236
159
 
237
160
    /**
238
 
     * Like {@link Message#getRepeatedFieldCount(Descriptors.FieldDescriptor)}
239
 
     */
240
 
    int getRepeatedFieldCount(Descriptors.FieldDescriptor field);
241
 
 
242
 
    /**
243
 
     * Like {@link Message#getRepeatedField(Descriptors.FieldDescriptor,int)}
244
 
     */
245
 
    Object getRepeatedField(Descriptors.FieldDescriptor field, int index);
246
 
 
247
 
    /**
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
262
175
     */
263
176
    Builder addRepeatedField(Descriptors.FieldDescriptor field, Object value);
264
177
 
265
 
    /** Get the {@link UnknownFieldSet} for this message. */
266
 
    UnknownFieldSet getUnknownFields();
267
 
 
268
178
    /** Set the {@link UnknownFieldSet} for this message. */
269
179
    Builder setUnknownFields(UnknownFieldSet unknownFields);
270
180