From: David Gageot Date: Wed, 30 May 2012 07:46:04 +0000 (+0200) Subject: Will this violation ever be fixed? X-Git-Tag: 3.1~34 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cf5979d56845d3c713d72b9de7aceea0b644da8e;p=sonarqube.git Will this violation ever be fixed? --- diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java index 6f7b924032e..bc6e52f72da 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java @@ -19,6 +19,8 @@ */ package org.sonar.server.startup; +import com.google.common.base.Strings; + import com.google.common.collect.Lists; import com.google.common.collect.Ordering; import org.slf4j.Logger; @@ -151,25 +153,19 @@ public final class RegisterNewDashboards { private static final long serialVersionUID = 0; @Override - public int compare(DashboardDto d1, DashboardDto d2) { - if ((d1 == null) && (d2 == null)) { - return 0; - } - if ((d1 == null) || (d1.getName() == null)) { - return +1; - } - if ((d2 == null) || (d2.getName() == null)) { - return -1; - } + public int compare(DashboardDto left, DashboardDto right) { + String leftName = (left == null) ? null : left.getName(); + String rightName = (right == null) ? null : right.getName(); // the default dashboard must be the first one to be activated - if (DEFAULT_DASHBOARD_NAME.equals(d1.getName())) { + if (DEFAULT_DASHBOARD_NAME.equals(leftName)) { return -1; } - if (DEFAULT_DASHBOARD_NAME.equals(d2.getName())) { + if (DEFAULT_DASHBOARD_NAME.equals(rightName)) { return 1; } - return d1.getName().compareTo(d2.getName()); + + return Ordering.natural().nullsLast().compare(leftName, rightName); } } }