Skip to content

Improve Performance by Avoiding Recalculating Constants #46

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
* Parent class of the Sunrise and Sunset calculator classes.
*/
public class SolarEventCalculator {
public static final BigDecimal RADIANS_TO_DEGREES_MULTIPLIER = new BigDecimal(180 / Math.PI);
public static final BigDecimal DEGREES_TO_RADIANS_MULTIPLIER = BigDecimal.valueOf(Math.PI / 180.0);
public static final BigDecimal HOURS_IN_DAY = BigDecimal.valueOf(24.0D);
final private Location location;
final private TimeZone timeZone;

Expand Down Expand Up @@ -304,7 +307,7 @@ private String getLocalTimeAsString(BigDecimal localTimeParam) {

BigDecimal localTime = localTimeParam;
if (localTime.compareTo(BigDecimal.ZERO) == -1) {
localTime = localTime.add(BigDecimal.valueOf(24.0D));
localTime = localTime.add(HOURS_IN_DAY);
}
String[] timeComponents = localTime.toPlainString().split("\\.");
int hour = Integer.parseInt(timeComponents[0]);
Expand Down Expand Up @@ -341,7 +344,7 @@ protected Calendar getLocalTimeAsCalendar(BigDecimal localTimeParam, Calendar da

BigDecimal localTime = localTimeParam;
if (localTime.compareTo(BigDecimal.ZERO) == -1) {
localTime = localTime.add(BigDecimal.valueOf(24.0D));
localTime = localTime.add(HOURS_IN_DAY);
resultTime.add(Calendar.HOUR_OF_DAY, -24);
}
String[] timeComponents = localTime.toPlainString().split("\\.");
Expand Down Expand Up @@ -385,11 +388,11 @@ private BigDecimal getArcCosineFor(BigDecimal radians) {
}

private BigDecimal convertRadiansToDegrees(BigDecimal radians) {
return multiplyBy(radians, new BigDecimal(180 / Math.PI));
return multiplyBy(radians, RADIANS_TO_DEGREES_MULTIPLIER);
}

private BigDecimal convertDegreesToRadians(BigDecimal degrees) {
return multiplyBy(degrees, BigDecimal.valueOf(Math.PI / 180.0));
return multiplyBy(degrees, DEGREES_TO_RADIANS_MULTIPLIER);
}

private BigDecimal multiplyBy(BigDecimal multiplicand, BigDecimal multiplier) {
Expand Down