From: Julien Lancelot Date: Wed, 19 Feb 2014 13:54:30 +0000 (+0100) Subject: HOURS_IN_DAY property should not be read in the constructor X-Git-Tag: 4.2~92 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9ffdd2a20af48014b9eda19e57100607d1b97409;p=sonarqube.git HOURS_IN_DAY property should not be read in the constructor --- diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java index 30e2e6c8187..6ed686036dc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java @@ -25,6 +25,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import javax.annotation.Nullable; + import java.io.Serializable; /** @@ -98,9 +99,9 @@ public class WorkDuration implements Serializable { static WorkDuration createFromSeconds(long seconds, int hoursInDay) { int days = (int) (seconds / hoursInDay / 60d / 60d); - long currentDurationInSeconds = seconds - (days * hoursInDay * 60 * 60); + long currentDurationInSeconds = seconds - (days * hoursInDay * 3600); int hours = (int) (currentDurationInSeconds / 60d / 60d); - currentDurationInSeconds = currentDurationInSeconds - (hours * 60 * 60); + currentDurationInSeconds = currentDurationInSeconds - (hours * 3600); int minutes = (int) (currentDurationInSeconds / 60d); return new WorkDuration(seconds, days, hours, minutes, hoursInDay); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDurationFactory.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDurationFactory.java index 9e84017fe90..7ecf0d83ba3 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDurationFactory.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDurationFactory.java @@ -30,18 +30,22 @@ import org.sonar.api.config.Settings; */ public final class WorkDurationFactory implements BatchComponent, ServerComponent { - private final int hoursInDay; + private final Settings settings; public WorkDurationFactory(Settings settings) { - this.hoursInDay = settings.getInt(CoreProperties.HOURS_IN_DAY); + this.settings = settings; } public WorkDuration createFromWorkingValue(int value, WorkDuration.UNIT unit) { - return WorkDuration.createFromValueAndUnit(value, unit, hoursInDay); + return WorkDuration.createFromValueAndUnit(value, unit, hoursInDay()); } public WorkDuration createFromWorkingLong(long duration) { - return WorkDuration.createFromLong(duration, hoursInDay); + return WorkDuration.createFromLong(duration, hoursInDay()); + } + + private int hoursInDay(){ + return settings.getInt(CoreProperties.HOURS_IN_DAY); } }