From 09354db1434859a31a3c81abebcc4018d42f2715 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Tue, 18 Jul 2017 15:38:30 -0700 Subject: Merge from Google internal for 3.4 release --- .../src/main/java/com/google/protobuf/util/Durations.java | 11 +++++++++++ .../src/main/java/com/google/protobuf/util/FieldMaskUtil.java | 9 ++++++--- .../src/main/java/com/google/protobuf/util/JsonFormat.java | 6 +++++- .../src/main/java/com/google/protobuf/util/Timestamps.java | 11 +++++++++++ .../test/java/com/google/protobuf/util/JsonFormatTest.java | 4 ++-- 5 files changed, 35 insertions(+), 6 deletions(-) (limited to 'java/util') diff --git a/java/util/src/main/java/com/google/protobuf/util/Durations.java b/java/util/src/main/java/com/google/protobuf/util/Durations.java index 46b21828..dc223d47 100644 --- a/java/util/src/main/java/com/google/protobuf/util/Durations.java +++ b/java/util/src/main/java/com/google/protobuf/util/Durations.java @@ -83,6 +83,17 @@ public final class Durations { return COMPARATOR; } + /** + * Compares two durations. The value returned is identical to what would be returned by: + * {@code Durations.comparator().compare(x, y)}. + * + * @return the value {@code 0} if {@code x == y}; a value less than {@code 0} if {@code x < y}; + * and a value greater than {@code 0} if {@code x > y} + */ + public static int compare(Duration x, Duration y) { + return COMPARATOR.compare(x, y); + } + /** * Returns true if the given {@link Duration} is valid. The {@code seconds} value must be in the * range [-315,576,000,000, +315,576,000,000]. The {@code nanos} value must be in the range diff --git a/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java b/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java index 21d11b2c..b2f849c4 100644 --- a/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java +++ b/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java @@ -311,16 +311,19 @@ public class FieldMaskUtil { return replacePrimitiveFields; } - public void setReplaceMessageFields(boolean value) { + public MergeOptions setReplaceMessageFields(boolean value) { replaceMessageFields = value; + return this; } - public void setReplaceRepeatedFields(boolean value) { + public MergeOptions setReplaceRepeatedFields(boolean value) { replaceRepeatedFields = value; + return this; } - public void setReplacePrimitiveFields(boolean value) { + public MergeOptions setReplacePrimitiveFields(boolean value) { replacePrimitiveFields = value; + return this; } } diff --git a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java index e1c2d73d..a603d96a 100644 --- a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java +++ b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java @@ -1686,7 +1686,11 @@ public class JsonFormat { } private ByteString parseBytes(JsonElement json) throws InvalidProtocolBufferException { - return ByteString.copyFrom(BaseEncoding.base64().decode(json.getAsString())); + try { + return ByteString.copyFrom(BaseEncoding.base64().decode(json.getAsString())); + } catch (IllegalArgumentException e) { + return ByteString.copyFrom(BaseEncoding.base64Url().decode(json.getAsString())); + } } private EnumValueDescriptor parseEnum(EnumDescriptor enumDescriptor, JsonElement json) diff --git a/java/util/src/main/java/com/google/protobuf/util/Timestamps.java b/java/util/src/main/java/com/google/protobuf/util/Timestamps.java index d0bac417..13136f30 100644 --- a/java/util/src/main/java/com/google/protobuf/util/Timestamps.java +++ b/java/util/src/main/java/com/google/protobuf/util/Timestamps.java @@ -114,6 +114,17 @@ public final class Timestamps { return COMPARATOR; } + /** + * Compares two timestamps. The value returned is identical to what would be returned by: + * {@code Timestamps.comparator().compare(x, y)}. + * + * @return the value {@code 0} if {@code x == y}; a value less than {@code 0} if {@code x < y}; + * and a value greater than {@code 0} if {@code x > y} + */ + public static int compare(Timestamp x, Timestamp y) { + return COMPARATOR.compare(x, y); + } + /** * Returns true if the given {@link Timestamp} is valid. The {@code seconds} value must be in the * range [-62,135,596,800, +253,402,300,799] (i.e., between 0001-01-01T00:00:00Z and diff --git a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java index 460b81f6..e4c5387a 100644 --- a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java @@ -73,7 +73,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Locale; -import java.util.Map; import java.util.Set; import junit.framework.TestCase; @@ -1144,7 +1143,8 @@ public class JsonFormatTest extends TestCase { } public void testParserAcceptBase64Variants() throws Exception { - assertAccepts("optionalBytes", "AQI"); + assertAccepts("optionalBytes", "AQI"); // No padding + assertAccepts("optionalBytes", "-_w"); // base64Url, no padding } public void testParserRejectInvalidEnumValue() throws Exception { -- cgit v1.2.3