|
|
|
@ -73,6 +73,36 @@ public abstract class GeneratedMessage extends AbstractMessage { |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isInitialized() { |
|
|
|
|
// Check that all required fields are present.
|
|
|
|
|
for (FieldDescriptor field : getDescriptorForType().getFields()) { |
|
|
|
|
if (field.isRequired()) { |
|
|
|
|
if (!hasField(field)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check that embedded messages are initialized.
|
|
|
|
|
for (FieldDescriptor field : getDescriptorForType().getFields()) { |
|
|
|
|
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { |
|
|
|
|
if (field.isRepeated()) { |
|
|
|
|
for (Message element : (List<Message>) getField(field)) { |
|
|
|
|
if (!element.isInitialized()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (!((Message) getField(field)).isInitialized()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Map<FieldDescriptor, Object> getAllFields() { |
|
|
|
|
return Collections.unmodifiableMap(getAllFieldsMutable()); |
|
|
|
@ -356,6 +386,10 @@ public abstract class GeneratedMessage extends AbstractMessage { |
|
|
|
|
protected boolean extensionsAreInitialized() { |
|
|
|
|
return extensions.isInitialized(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isInitialized() { |
|
|
|
|
return super.isInitialized() && extensionsAreInitialized(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Used by subclasses to serialize extensions. Extension ranges may be |
|
|
|
|