-
Notifications
You must be signed in to change notification settings - Fork 624
Add an ObjectValue builder #1150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an ObjectValue builder #1150
Conversation
Codecov Report
Continue to review full report at Codecov.
|
@@ -117,7 +117,7 @@ public ParsedUpdateData parseUpdateData(Map<String, Object> data) { | |||
|
|||
ParseAccumulator accumulator = new ParseAccumulator(UserData.Source.Update); | |||
ParseContext context = accumulator.rootContext(); | |||
ObjectValue updateData = ObjectValue.emptyObject(); | |||
ObjectValue.Builder updateData = ObjectValue.Builder.emptyBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty verbose. How about ObjectValue.newBuilder()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me. I got inspired by the rest of the Protobuf API.
for (int i = 0; i < fieldTransforms.size(); i++) { | ||
FieldTransform fieldTransform = fieldTransforms.get(i); | ||
FieldPath fieldPath = fieldTransform.getFieldPath(); | ||
objectValue = objectValue.set(fieldPath, transformResults.get(i)); | ||
builder.set(fieldPath, transformResults.get(i)).build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing .build()
here seems wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
@@ -356,4 +374,12 @@ public void testValueOrdering() { | |||
.addEqualityGroup(wrapObject(map("foo", "0"))) | |||
.testCompare(); | |||
} | |||
|
|||
private ObjectValue setField(ObjectValue empty, String a, FieldValue mod) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The caller doesn't necessarily have to pass an empty object, do they? Seems like empty
could be objectValue
, as it is below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it should have been objectValue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR is meant to pave the way for a mutable ObjectValue that is based on a Value.Builder. It proves that we only need
set()
anddelete()
(and notequals()
andcompareTo()
) on the mutable type since most parts of the code still deal with immutable ObjectValues.This is meant for an feature branch until we finish the Proto conversion as ObjectValue.Builder().set() is somewhat inefficient for nested field updates.