]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 4 Mar 2014 08:30:21 +0000 (09:30 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 4 Mar 2014 08:30:21 +0000 (09:30 +0100)
sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java
sonar-core/src/main/java/org/sonar/core/i18n/WorkDurationFormatter.java
sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogFormatter.java
sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java

index 8737323a147eee4c16ddb8c8dcd6588d90c967b8..8be028d41346b4e41e5ecd07bb1b9bd2fe0e0747 100644 (file)
@@ -155,7 +155,7 @@ public class DefaultI18n implements I18n, ServerExtension, BatchExtension, Start
     List<WorkDurationFormatter.Result> results = workDurationFormatter.format(duration);
     StringBuilder message = new StringBuilder();
     for (WorkDurationFormatter.Result result : results) {
-      if (result.key().equals(" ")) {
+      if (" ".equals(result.key())) {
         message.append(" ");
       } else {
         message.append(message(locale, result.key(), null, result.value()));
index 16e0713c5fa6197b7dea5c7f443534c725c7397c..af7b709e5d56dfc16420ee84e1f11cc792dae9fa 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.api.utils.WorkDuration;
 import org.sonar.api.utils.WorkDurationFactory;
 
 import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 
 import java.util.List;
 
@@ -41,32 +42,37 @@ public class WorkDurationFormatter implements ServerComponent, BatchExtension {
     this.workDurationFactory = workDurationFactory;
   }
 
-  public List<Result> format(long durationInSeconds) {
-    List<Result> results = newArrayList();
-    if (durationInSeconds == 0) {
+  public List<Result> format(long durationInMinutes) {
+    if (durationInMinutes == 0) {
       return newArrayList(new Result("0", null));
     }
-    boolean isNegative = durationInSeconds < 0;
-    Long absDuration = Math.abs(durationInSeconds);
-    WorkDuration workDuration = workDurationFactory.createFromMinutes(absDuration);
+    boolean isNegative = durationInMinutes < 0;
+    Long absDuration = Math.abs(durationInMinutes);
+    return format(workDurationFactory.createFromMinutes(absDuration), isNegative);
+  }
+
+  private List<Result> format(WorkDuration workDuration, boolean isNegative) {
+    List<Result> results = newArrayList();
     if (workDuration.days() > 0) {
       results.add(message("work_duration.x_days", isNegative ? -1 * workDuration.days() : workDuration.days()));
     }
     if (workDuration.hours() > 0 && workDuration.days() < 10) {
-      if (!results.isEmpty()) {
-        results.add(new Result(" ", null));
-      }
+      addSpaceIfNeeded(results);
       results.add(message("work_duration.x_hours", isNegative && results.isEmpty() ? -1 * workDuration.hours() : workDuration.hours()));
     }
     if (workDuration.minutes() > 0 && workDuration.hours() < 10 && workDuration.days() == 0) {
-      if (!results.isEmpty()) {
-        results.add(new Result(" ", null));
-      }
+      addSpaceIfNeeded(results);
       results.add(message("work_duration.x_minutes", isNegative && results.isEmpty() ? -1 * workDuration.minutes() : workDuration.minutes()));
     }
     return results;
   }
 
+  private void addSpaceIfNeeded(List<Result> results){
+    if (!results.isEmpty()) {
+      results.add(new Result(" ", null));
+    }
+  }
+
   private Result message(String key, @CheckForNull Object parameter) {
     return new Result(key, parameter);
   }
@@ -75,7 +81,7 @@ public class WorkDurationFormatter implements ServerComponent, BatchExtension {
     private String key;
     private Object value;
 
-    Result(String key, Object value) {
+    Result(String key, @Nullable Object value) {
       this.key = key;
       this.value = value;
     }
@@ -84,6 +90,7 @@ public class WorkDurationFormatter implements ServerComponent, BatchExtension {
       return key;
     }
 
+    @CheckForNull
     Object value() {
       return value;
     }
index fde05c3068fb0d9d6d2348b17037d5aca6305c4c..d33f3089aeae52614fe0cb0569d23091643d19e5 100644 (file)
@@ -74,7 +74,6 @@ public class IssueChangelogFormatter implements ServerComponent {
         newValueString = i18n.formatWorkDuration(UserSession.get().locale(), Long.parseLong(newValueString));
       }
       if (oldValueString != null) {
-        // TODO use i18n API
         oldValueString = i18n.formatWorkDuration(UserSession.get().locale(), Long.parseLong(oldValueString));
       }
     }
index d955b8d5ab8f6ea3561f488640f45d3c08977cbd..0f588f7fd471b759ea411f4358446bd80bd69bb4 100644 (file)
@@ -137,9 +137,8 @@ public class IssueShowWsHandler implements RequestHandler {
 
     String projectName = project != null ? project.longName() != null ? project.longName() : project.name() : null;
     // Do not display sub project long name if sub project and project are the same
-    String subProjectName = subProject != null && project != null && !subProject.getId().equals(project.getId()) ?
-      subProject.longName() != null ? subProject.longName() : subProject.name() :
-      null;
+    boolean shoudDisplaySubProjectLongName = subProject != null && project != null && !subProject.getId().equals(project.getId());
+    String subProjectName = shoudDisplaySubProjectLongName ? subProject.longName() != null ? subProject.longName() : subProject.name() : null;
 
     json
       .prop("component", issue.componentKey())