Skip to content
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

Refactor changes #880

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

tanujdoshi
Copy link

@tanujdoshi tanujdoshi commented Mar 29, 2024

Hi @stleary

I have refactored some changes in following files : -

  1. populateMap method in JSONObject Decompose Conditional : -
  • There was complex condition which i have moved to another method name : isValidMethod COMMIT_LINK
  1. Rename variables in nextToken() method of HTTPTOkener file
  • There were two variables name c, and q i have renamed them COMMIT_LINK
  1. Extract method in toString() of HTTP
  • toString() method was long, i have divided that method for more readibility. COMMIT_LINK

@@ -1806,6 +1801,15 @@ && isValidMethodName(method.getName())) {
}
}

private boolean isValidMethod(int modifiers,Method method) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a JavaDoc comment to this new method.

@@ -113,24 +113,38 @@ public static JSONObject toJSONObject(String string) throws JSONException {
public static String toString(JSONObject jo) throws JSONException {
StringBuilder sb = new StringBuilder();
if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {
sb.append(jo.getString("HTTP-Version"));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that the refactoring update in this method is a good idea. Although it shortens the method, it hides a more interesting potential refactoring - notice how many times status-code, reason-phrase, method, request-uri, and http-version are referenced in the conditionals. It makes the code look half-finished. Can you come up with a way to reduce the number of conditions being checked without affecting the output ordering?

@@ -1762,12 +1762,7 @@ private void populateMap(Object bean, Set<Object> objectsRecord) {
Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
for (final Method method : methods) {
final int modifiers = method.getModifiers();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable modifiers is only used with the method isValidMethod. So there is no need for this local variable here.
Instead, it should be a variable inside the method isValidMethod and the parameter should be removed from the method signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants