diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2014-02-25 11:24:45 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2014-02-25 19:02:54 +0100 |
commit | f359a4283c663ebff7416bb003895ebde323e8d0 (patch) | |
tree | bfcd66f17dbfb17cf5de057908c1ec833b178268 /sonar-plugin-api/src | |
parent | b102e79cb3bf76e6d5eab14fd767d967c2fb84e6 (diff) | |
download | sonarqube-f359a4283c663ebff7416bb003895ebde323e8d0.tar.gz sonarqube-f359a4283c663ebff7416bb003895ebde323e8d0.zip |
SONAR-4996 Save debt on issues and measures in minutes (instead of seconds)
Diffstat (limited to 'sonar-plugin-api/src')
4 files changed, 49 insertions, 44 deletions
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 a564f244e45..1f8703ebfe5 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,7 +25,6 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import javax.annotation.Nullable; - import java.io.Serializable; /** @@ -43,13 +42,13 @@ public class WorkDuration implements Serializable { private int hoursInDay; - private long durationInSeconds; + private long durationInMinutes; private int days; private int hours; private int minutes; - private WorkDuration(long durationInSeconds, int days, int hours, int minutes, int hoursInDay) { - this.durationInSeconds = durationInSeconds; + private WorkDuration(long durationInMinutes, int days, int hours, int minutes, int hoursInDay) { + this.durationInMinutes = durationInMinutes; this.days = days; this.hours = hours; this.minutes = minutes; @@ -57,9 +56,9 @@ public class WorkDuration implements Serializable { } public static WorkDuration create(int days, int hours, int minutes, int hoursInDay) { - long durationInSeconds = 3600L * days * hoursInDay; - durationInSeconds += 3600L * hours; - durationInSeconds += 60L * minutes; + long durationInSeconds = 60L * days * hoursInDay; + durationInSeconds += 60L * hours; + durationInSeconds += minutes; return new WorkDuration(durationInSeconds, days, hours, minutes, hoursInDay); } @@ -99,13 +98,12 @@ public class WorkDuration implements Serializable { return WorkDuration.create(days, hours, minutes, hoursInDay); } - static WorkDuration createFromSeconds(long seconds, int hoursInDay) { - int days = (int) (seconds / hoursInDay / 60f / 60f); - long currentDurationInSeconds = seconds - (3600L * days * hoursInDay); - int hours = (int) (currentDurationInSeconds / 60f / 60f); - currentDurationInSeconds = currentDurationInSeconds - (3600L * hours); - int minutes = (int) (currentDurationInSeconds / 60f); - return new WorkDuration(seconds, days, hours, minutes, hoursInDay); + static WorkDuration createFromMinutes(long duration, int hoursInDay) { + int days = ((Double) (duration / hoursInDay / 60d)).intValue(); + Long currentDurationInMinutes = duration - (60L * days * hoursInDay); + int hours = ((Double) (currentDurationInMinutes / 60d)).intValue(); + currentDurationInMinutes = currentDurationInMinutes - (60L * hours); + return new WorkDuration(duration, days, hours, currentDurationInMinutes.intValue(), hoursInDay); } /** @@ -113,7 +111,7 @@ public class WorkDuration implements Serializable { * For instance, 3 days and 4 hours will return 3.5 days (if hoursIndDay is 8). */ public double toWorkingDays() { - return durationInSeconds / 60d / 60d / hoursInDay; + return durationInMinutes / 60d / hoursInDay; } /** @@ -131,13 +129,13 @@ public class WorkDuration implements Serializable { return workingDays * DAY_POSITION_IN_LONG + workingHours * HOUR_POSITION_IN_LONG + minutes * MINUTE_POSITION_IN_LONG; } - public long toSeconds() { - return durationInSeconds; + public long toMinutes() { + return durationInMinutes; } public WorkDuration add(@Nullable WorkDuration with) { if (with != null) { - return WorkDuration.createFromSeconds(this.toSeconds() + with.toSeconds(), this.hoursInDay); + return WorkDuration.createFromMinutes(this.toMinutes() + with.toMinutes(), this.hoursInDay); } else { return this; } @@ -145,14 +143,14 @@ public class WorkDuration implements Serializable { public WorkDuration subtract(@Nullable WorkDuration with) { if (with != null) { - return WorkDuration.createFromSeconds(this.toSeconds() - with.toSeconds(), this.hoursInDay); + return WorkDuration.createFromMinutes(this.toMinutes() - with.toMinutes(), this.hoursInDay); } else { return this; } } public WorkDuration multiply(int factor) { - return WorkDuration.createFromSeconds(this.toSeconds() * factor, this.hoursInDay); + return WorkDuration.createFromMinutes(this.toMinutes() * factor, this.hoursInDay); } public int days() { @@ -182,7 +180,7 @@ public class WorkDuration implements Serializable { } WorkDuration that = (WorkDuration) o; - if (durationInSeconds != that.durationInSeconds) { + if (durationInMinutes != that.durationInMinutes) { return false; } @@ -191,7 +189,7 @@ public class WorkDuration implements Serializable { @Override public int hashCode() { - return (int) (durationInSeconds ^ (durationInSeconds >>> 32)); + return (int) (durationInMinutes ^ (durationInMinutes >>> 32)); } @Override 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 b86ee4fbf96..13175191bb7 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 @@ -55,8 +55,8 @@ public final class WorkDurationFactory implements BatchComponent, ServerComponen /** * @since 4.3 */ - public WorkDuration createFromSeconds(long durationInSeconds) { - return WorkDuration.createFromSeconds(durationInSeconds, hoursInDay()); + public WorkDuration createFromMinutes(long duration) { + return WorkDuration.createFromMinutes(duration, hoursInDay()); } private int hoursInDay(){ diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java index ae289085b8f..c9b1652903d 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java @@ -31,19 +31,22 @@ public class WorkDurationFactoryTest { WorkDurationFactory factory; + static final int HOURS_IN_DAY = 8; + static final Long ONE_HOUR_IN_MINUTES = 1L * 60; + @Before public void setUp() throws Exception { Settings settings = new Settings(); - settings.setProperty(CoreProperties.HOURS_IN_DAY, 8); + settings.setProperty(CoreProperties.HOURS_IN_DAY, HOURS_IN_DAY); factory = new WorkDurationFactory(settings); } @Test public void create_from_working_value() throws Exception { // 1 working day -> 8 hours - assertThat(factory.createFromWorkingValue(1, WorkDuration.UNIT.DAYS).toSeconds()).isEqualTo(8 * 60 * 60); + assertThat(factory.createFromWorkingValue(1, WorkDuration.UNIT.DAYS).toMinutes()).isEqualTo(8L * ONE_HOUR_IN_MINUTES); // 8 hours - assertThat(factory.createFromWorkingValue(8, WorkDuration.UNIT.HOURS).toSeconds()).isEqualTo(8 * 60 * 60); + assertThat(factory.createFromWorkingValue(8, WorkDuration.UNIT.HOURS).toMinutes()).isEqualTo(8L * ONE_HOUR_IN_MINUTES); } @Test @@ -56,7 +59,7 @@ public class WorkDurationFactoryTest { @Test public void create_from_seconds() throws Exception { - WorkDuration workDuration = factory.createFromSeconds(8 * 60 * 60L); + WorkDuration workDuration = factory.createFromMinutes(8L * ONE_HOUR_IN_MINUTES); assertThat(workDuration.days()).isEqualTo(1); assertThat(workDuration.hours()).isEqualTo(0); assertThat(workDuration.minutes()).isEqualTo(0); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java index affb52a1b17..22ad1125a36 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java @@ -26,7 +26,11 @@ import static org.fest.assertions.Assertions.assertThat; public class WorkDurationTest { - private static final int HOURS_IN_DAY = 8; + static final int HOURS_IN_DAY = 8; + + static final Long ONE_MINUTE = 1L; + static final Long ONE_HOUR_IN_MINUTES = ONE_MINUTE * 60; + static final Long ONE_DAY_IN_MINUTES = ONE_HOUR_IN_MINUTES * HOURS_IN_DAY; @Test public void create_from_days_hours_minutes() throws Exception { @@ -34,7 +38,7 @@ public class WorkDurationTest { assertThat(workDuration.days()).isEqualTo(1); assertThat(workDuration.hours()).isEqualTo(1); assertThat(workDuration.minutes()).isEqualTo(1); - assertThat(workDuration.toSeconds()).isEqualTo(1 * HOURS_IN_DAY * 60 * 60 + 1 * 60 * 60 + 60); + assertThat(workDuration.toMinutes()).isEqualTo(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE); assertThat(workDuration.hoursInDay()).isEqualTo(HOURS_IN_DAY); } @@ -45,26 +49,26 @@ public class WorkDurationTest { assertThat(result.hours()).isEqualTo(0); assertThat(result.minutes()).isEqualTo(0); assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); - assertThat(result.toSeconds()).isEqualTo(1 * HOURS_IN_DAY * 60 * 60); + assertThat(result.toMinutes()).isEqualTo(ONE_DAY_IN_MINUTES); - assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toSeconds()).isEqualTo(1 * HOURS_IN_DAY * 60 * 60); - assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toSeconds()).isEqualTo(1 * 60 * 60); - assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toSeconds()).isEqualTo(60); + assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toMinutes()).isEqualTo(ONE_DAY_IN_MINUTES); + assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toMinutes()).isEqualTo(ONE_HOUR_IN_MINUTES); + assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toMinutes()).isEqualTo(ONE_MINUTE); } @Test - public void create_from_seconds() throws Exception { - WorkDuration workDuration = WorkDuration.createFromSeconds(60, HOURS_IN_DAY); + public void create_from_minutes() throws Exception { + WorkDuration workDuration = WorkDuration.createFromMinutes(ONE_MINUTE, HOURS_IN_DAY); assertThat(workDuration.days()).isEqualTo(0); assertThat(workDuration.hours()).isEqualTo(0); assertThat(workDuration.minutes()).isEqualTo(1); - workDuration = WorkDuration.createFromSeconds(60 * 60, HOURS_IN_DAY); + workDuration = WorkDuration.createFromMinutes(ONE_HOUR_IN_MINUTES, HOURS_IN_DAY); assertThat(workDuration.days()).isEqualTo(0); assertThat(workDuration.hours()).isEqualTo(1); assertThat(workDuration.minutes()).isEqualTo(0); - workDuration = WorkDuration.createFromSeconds(HOURS_IN_DAY * 60 * 60, HOURS_IN_DAY); + workDuration = WorkDuration.createFromMinutes(ONE_DAY_IN_MINUTES, HOURS_IN_DAY); assertThat(workDuration.days()).isEqualTo(1); assertThat(workDuration.hours()).isEqualTo(0); assertThat(workDuration.minutes()).isEqualTo(0); @@ -73,19 +77,19 @@ public class WorkDurationTest { @Test public void create_from_working_long() throws Exception { // 1 minute - WorkDuration workDuration = WorkDuration.createFromLong(1l, HOURS_IN_DAY); + WorkDuration workDuration = WorkDuration.createFromLong(1L, HOURS_IN_DAY); assertThat(workDuration.days()).isEqualTo(0); assertThat(workDuration.hours()).isEqualTo(0); assertThat(workDuration.minutes()).isEqualTo(1); // 1 hour - workDuration = WorkDuration.createFromLong(100l, HOURS_IN_DAY); + workDuration = WorkDuration.createFromLong(100L, HOURS_IN_DAY); assertThat(workDuration.days()).isEqualTo(0); assertThat(workDuration.hours()).isEqualTo(1); assertThat(workDuration.minutes()).isEqualTo(0); // 1 day - workDuration = WorkDuration.createFromLong(10000l, HOURS_IN_DAY); + workDuration = WorkDuration.createFromLong(10000L, HOURS_IN_DAY); assertThat(workDuration.days()).isEqualTo(1); assertThat(workDuration.hours()).isEqualTo(0); assertThat(workDuration.minutes()).isEqualTo(0); @@ -93,9 +97,9 @@ public class WorkDurationTest { @Test public void convert_to_seconds() throws Exception { - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toSeconds()).isEqualTo(2 * 60); - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toSeconds()).isEqualTo(2 * 60 * 60); - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toSeconds()).isEqualTo(2 * HOURS_IN_DAY * 60 * 60); + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toMinutes()).isEqualTo(2L * ONE_MINUTE); + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toMinutes()).isEqualTo(2L * ONE_HOUR_IN_MINUTES); + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toMinutes()).isEqualTo(2L * ONE_DAY_IN_MINUTES); } @Test |