-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 isEmpty and isNotEmpty methods #421
Conversation
No other collection type in Java has a JSONObject example = new JSONObject();
example.length() == 0; // was
example.isEmpty(); // become
example.length() != 0; // was
example.isNotEmpty(); // become
List<JSONObject> list = ...;
list.stream().filter(JSONObject::isEmpty).filter(item -> !item.isEmpty()).count(); |
@johnjaylward Arguably, but Scala collections/strings/option have nonEmpty method as part of standard API as well. May be we need more opinions. |
No objection to adding isEmpty(), but please do it the right way:
I don't think there is a valid use case for isNotEmpty(). |
Will update tests later. |
Starting 3 day comment window |
@stleary If we want to ensure Android compatability, then the other classes should not be updated, only JSONArray and JSONObject. i.e. if using the CDL class in android, you'll get a no method exception for isEmpty. |
My bad, thanks @johnjaylward. @strkkk please revert the changes to CDL, JSONML, and XML. I will need to update the Wiki regarding Android compatibility. |
Ok, I will change it. |
@stleary |
What problem does this code solve?
It is clearer to check if object is empty or not by calling method rather then comparing length.
Also, it can be used as method reference, see code snippet below.
Risks
Low
Changes to the API?
Yes
Will this require a new release?
No
Should the documentation be updated?
Methods are added with javadocs
Does it break the unit tests?
No. This methods are new.
Was any code refactored in this commit?
NoInternal uses of length() == 0 and similar code were converted to isEmpty()Review status
APPROVED
(isNotEmpty() is not included, JSONArray.isEmpty() was added)
Starting 3 day comment window