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
json patches introduced to the OpenJDK copy in JDK-8246435 #636
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
@@ -39,6 +39,24 @@ public JSONArray(JSONValue[] array) { | ||
} | ||
} | ||
|
||
private void append(JSONValue value) { | ||
if (value instanceof JSONArray) { | ||
for (var v : value.asArray()) { | ||
append(v); | ||
} | ||
} else { | ||
this.values.add(value); | ||
} | ||
} | ||
|
||
public JSONArray(JSONValue value, JSONValue... values) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to the comment about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't care about a non-flattening constructor. You can add one if you need one. But I can change it to a static factory method instead, if you want. It's probably clearer, given that we can agree on a suitable name. (I'll accept "concat" if you insist, but I'm not persuaded that it's really better...) |
||
this.values = new ArrayList<JSONValue>(values.length + 1); | ||
append(value); | ||
for (var v : values) { | ||
append(v); | ||
} | ||
} | ||
|
||
public JSONArray(List<JSONValue> values) { | ||
this.values = new ArrayList<JSONValue>(values); | ||
} | ||
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.
Could you rename this to
concat
and explicitly take aJSONArray
instead as parameter? I'm fine with havingappend
, butappend
should be justappend
(that is, append a single item to the array).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.
To me there's no deeper semantic difference between "append" and "concat". To be precise, this method do a flattening append/concat, and should probably be named something like addAndFlatten to be completely unambiguous. But that kind of naming did not seem to fit in with the rest of the design here.
If you insist that "concat" means "flatten while adding" but "append" does not, sure, I can rename it.
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.
Ah, sorry, now I see what you mean. You want a concat(JSONArray a) instead. Well, it might be good to have, but that does not really solve my problem, does it? :-)
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.
Well, if you have
append(JSONValue v)
andconcat(JSONArray a)
then code using such an API can easily have the code:I'm fine with having
appendOrConcat
inJSONArray
as well, but then I want it namedappendOrConcat
, notappend
. I agree thatappend
is shorter, but it is too misleading of a name IMHO for a method that really doesappendOrConcat
.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.
I still don't get it. Your example code would not recursively inline arrays; it will only work for a single nested layer. I can't see how that would be helpful to anything but the most specific situations. What is it you want to achieve?