1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 package com.google.protobuf;
33 import java.util.List;
37 * Base interface for methods common to {@link Message} and
38 * {@link Message.Builder} to provide type equivalency.
40 * @author jonp@google.com (Jon Perlow)
42 public interface MessageOrBuilder extends MessageLiteOrBuilder {
44 // (From MessageLite, re-declared here only for return type covariance.)
45 //@Override (Java 1.6 override semantics, but we must support 1.5)
46 Message getDefaultInstanceForType();
49 * Returns a list of field paths (e.g. "foo.bar.baz") of required fields
50 * which are not set in this message. You should call
51 * {@link MessageLiteOrBuilder#isInitialized()} first to check if there
52 * are any missing fields, as that method is likely to be much faster
53 * than this one even when the message is fully-initialized.
55 List<String> findInitializationErrors();
58 * Returns a comma-delimited list of required fields which are not set
59 * in this message object. You should call
60 * {@link MessageLiteOrBuilder#isInitialized()} first to check if there
61 * are any missing fields, as that method is likely to be much faster
62 * than this one even when the message is fully-initialized.
64 String getInitializationErrorString();
67 * Get the message's type's descriptor. This differs from the
68 * {@code getDescriptor()} method of generated message classes in that
69 * this method is an abstract method of the {@code Message} interface
70 * whereas {@code getDescriptor()} is a static method of a specific class.
71 * They return the same thing.
73 Descriptors.Descriptor getDescriptorForType();
76 * Returns a collection of all the fields in this message which are set
77 * and their corresponding values. A singular ("required" or "optional")
78 * field is set iff hasField() returns true for that field. A "repeated"
79 * field is set iff getRepeatedFieldCount() is greater than zero. The
80 * values are exactly what would be returned by calling
81 * {@link #getField(Descriptors.FieldDescriptor)} for each field. The map
82 * is guaranteed to be a sorted map, so iterating over it will return fields
83 * in order by field number.
85 * If this is for a builder, the returned map may or may not reflect future
86 * changes to the builder. Either way, the returned map is itself
89 Map<Descriptors.FieldDescriptor, Object> getAllFields();
92 * Returns true if the given oneof is set.
93 * @throws IllegalArgumentException if
94 * {@code oneof.getContainingType() != getDescriptorForType()}.
96 boolean hasOneof(Descriptors.OneofDescriptor oneof);
99 * Obtains the FieldDescriptor if the given oneof is set. Returns null
100 * if no field is set.
102 Descriptors.FieldDescriptor getOneofFieldDescriptor(
103 Descriptors.OneofDescriptor oneof);
106 * Returns true if the given field is set. This is exactly equivalent to
107 * calling the generated "has" accessor method corresponding to the field.
108 * @throws IllegalArgumentException The field is a repeated field, or
109 * {@code field.getContainingType() != getDescriptorForType()}.
111 boolean hasField(Descriptors.FieldDescriptor field);
114 * Obtains the value of the given field, or the default value if it is
115 * not set. For primitive fields, the boxed primitive value is returned.
116 * For enum fields, the EnumValueDescriptor for the value is returned. For
117 * embedded message fields, the sub-message is returned. For repeated
118 * fields, a java.util.List is returned.
120 Object getField(Descriptors.FieldDescriptor field);
123 * Gets the number of elements of a repeated field. This is exactly
124 * equivalent to calling the generated "Count" accessor method corresponding
126 * @throws IllegalArgumentException The field is not a repeated field, or
127 * {@code field.getContainingType() != getDescriptorForType()}.
129 int getRepeatedFieldCount(Descriptors.FieldDescriptor field);
132 * Gets an element of a repeated field. For primitive fields, the boxed
133 * primitive value is returned. For enum fields, the EnumValueDescriptor
134 * for the value is returned. For embedded message fields, the sub-message
136 * @throws IllegalArgumentException The field is not a repeated field, or
137 * {@code field.getContainingType() != getDescriptorForType()}.
139 Object getRepeatedField(Descriptors.FieldDescriptor field, int index);
141 /** Get the {@link UnknownFieldSet} for this message. */
142 UnknownFieldSet getUnknownFields();