-
Notifications
You must be signed in to change notification settings - Fork 418
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
Efficiency and better use of API #916
base: master
Are you sure you want to change the base?
Conversation
@@ -92,7 +92,7 @@ public static int ceil(float floatNumber) { | |||
} | |||
|
|||
public static int clamp(int check, int min, int max) { | |||
return check > max ? max : (check < min ? min : check); | |||
return check > max ? max : (Math.max(check, min)); |
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 method can be removed since there is an identical one in NukkitMath
@@ -47,18 +47,18 @@ public static double round(double d, int precision) { | |||
} | |||
|
|||
public static double clamp(double value, double min, double max) { | |||
return value < min ? min : (value > max ? max : value); | |||
return value < min ? min : (Math.min(value, max)); |
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.
Makes more sense to keep the operators in this class.
} | ||
|
||
public static int clamp(int value, int min, int max) { | ||
return value < min ? min : (value > max ? max : value); | ||
return value < min ? min : (Math.min(value, max)); |
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.
Same here
} | ||
|
||
public static double getDirection(double diffX, double diffZ) { | ||
diffX = Math.abs(diffX); | ||
diffZ = Math.abs(diffZ); | ||
|
||
return diffX > diffZ ? diffX : diffZ; | ||
return Math.max(diffX, diffZ); |
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.
And here
switch (this.type) { | ||
case Config.PROPERTIES: | ||
content = this.writeProperties(); | ||
content = new StringBuilder(this.writeProperties()); |
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.
StringBuilder
has already been initialised above.
break; | ||
case Config.JSON: | ||
content = new GsonBuilder().setPrettyPrinting().create().toJson(this.config); | ||
content = new StringBuilder(new GsonBuilder().setPrettyPrinting().create().toJson(this.config)); |
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.
Same here
break; | ||
case Config.YAML: | ||
DumperOptions dumperOptions = new DumperOptions(); | ||
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); | ||
Yaml yaml = new Yaml(dumperOptions); | ||
content = yaml.dump(this.config); | ||
content = new StringBuilder(yaml.dump(this.config)); |
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.
And here
No description provided.