Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
diff --git a/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
index 535be0fa359b7e9ccfc962279b2f1921f4ecdc74..969615210c4fceeb265107e1ec0bbd9cb3d2f4fb 100644
--- a/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
+++ b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
@@ -119,7 +119,7 @@ public class FieldMaskUtil {
/**
* Constructs a FieldMask from the passed field numbers.
*
- * @throws IllegalArugmentException if any of the fields are invalid for the message.
+ * @throws IllegalArgumentException if any of the fields are invalid for the message.
*/
public static FieldMask fromFieldNumbers(Class<? extends Message> type, int... fieldNumbers) {
return fromFieldNumbers(type, Ints.asList(fieldNumbers));
@@ -128,7 +128,7 @@ public class FieldMaskUtil {
/**
* Constructs a FieldMask from the passed field numbers.
*
- * @throws IllegalArugmentException if any of the fields are invalid for the message.
+ * @throws IllegalArgumentException if any of the fields are invalid for the message.
*/
public static FieldMask fromFieldNumbers(
Class<? extends Message> type, Iterable<Integer> fieldNumbers) {
@@ -211,14 +211,19 @@ public class FieldMaskUtil {
public static FieldMask normalize(FieldMask mask) {
return new FieldMaskTree(mask).toFieldMask();
}
-
+
/**
- * Creates an union of two FieldMasks.
+ * Creates a union of two or more FieldMasks.
*/
- public static FieldMask union(FieldMask mask1, FieldMask mask2) {
- return new FieldMaskTree(mask1).mergeFromFieldMask(mask2).toFieldMask();
+ public static FieldMask union(
+ FieldMask firstMask, FieldMask secondMask, FieldMask... otherMasks) {
+ FieldMaskTree maskTree = new FieldMaskTree(firstMask).mergeFromFieldMask(secondMask);
+ for (FieldMask mask : otherMasks) {
+ maskTree.mergeFromFieldMask(mask);
+ }
+ return maskTree.toFieldMask();
}
-
+
/**
* Calculates the intersection of two FieldMasks.
*/
@@ -237,6 +242,9 @@ public class FieldMaskUtil {
public static final class MergeOptions {
private boolean replaceMessageFields = false;
private boolean replaceRepeatedFields = false;
+ // TODO(b/28277137): change the default behavior to always replace primitive fields after
+ // fixing all failing TAP tests.
+ private boolean replacePrimitiveFields = false;
/**
* Whether to replace message fields (i.e., discard existing content in
@@ -257,7 +265,23 @@ public class FieldMaskUtil {
public boolean replaceRepeatedFields() {
return replaceRepeatedFields;
}
-
+
+ /**
+ * Whether to replace primitive (non-repeated and non-message) fields in
+ * destination message fields with the source primitive fields (i.e., if the
+ * field is set in the source, the value is copied to the
+ * destination; if the field is unset in the source, the field is cleared
+ * from the destination) when merging.
+ *
+ * <p>Default behavior is to always set the value of the source primitive
+ * field to the destination primitive field, and if the source field is
+ * unset, the default value of the source field is copied to the
+ * destination.
+ */
+ public boolean replacePrimitiveFields() {
+ return replacePrimitiveFields;
+ }
+
public void setReplaceMessageFields(boolean value) {
replaceMessageFields = value;
}
@@ -265,10 +289,15 @@ public class FieldMaskUtil {
public void setReplaceRepeatedFields(boolean value) {
replaceRepeatedFields = value;
}
+
+ public void setReplacePrimitiveFields(boolean value) {
+ replacePrimitiveFields = value;
+ }
}
-
+
/**
- * Merges fields specified by a FieldMask from one message to another.
+ * Merges fields specified by a FieldMask from one message to another with the
+ * specified merge options.
*/
public static void merge(FieldMask mask, Message source,
Message.Builder destination, MergeOptions options) {

Powered by Google App Engine
This is Rietveld 408576698