From c2d861021735484aa28a26e5ce0266ee2051015b Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 25 May 2012 13:04:11 +0200 Subject: [PATCH] Remove warnings --- .../sonar/server/filters/FilterExecutor.java | 3 +- .../sonar/server/filters/FilterResult.java | 45 ++++++++++--------- .../server/filters/FilterExecutorTest.java | 3 +- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/filters/FilterExecutor.java b/sonar-server/src/main/java/org/sonar/server/filters/FilterExecutor.java index 1ee75070fb2..4fe443510e8 100644 --- a/sonar-server/src/main/java/org/sonar/server/filters/FilterExecutor.java +++ b/sonar-server/src/main/java/org/sonar/server/filters/FilterExecutor.java @@ -33,6 +33,7 @@ import org.sonar.core.persistence.dialect.Dialect; import org.sonar.core.persistence.dialect.MsSql; import javax.persistence.Query; + import java.util.Collections; public class FilterExecutor implements ServerComponent { @@ -53,7 +54,7 @@ public class FilterExecutor implements ServerComponent { public FilterResult execute(Filter filter) { if (filter.mustReturnEmptyResult()) { - return new FilterResult(filter, Collections.emptyList()); + return new FilterResult(filter, Collections. emptyList()); } String sql = null; diff --git a/sonar-server/src/main/java/org/sonar/server/filters/FilterResult.java b/sonar-server/src/main/java/org/sonar/server/filters/FilterResult.java index 421e53f138e..87987537c0f 100644 --- a/sonar-server/src/main/java/org/sonar/server/filters/FilterResult.java +++ b/sonar-server/src/main/java/org/sonar/server/filters/FilterResult.java @@ -19,17 +19,21 @@ */ package org.sonar.server.filters; -import org.apache.commons.collections.comparators.ReverseComparator; +import com.google.common.collect.Ordering; import java.io.Serializable; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; public class FilterResult { private List rows; private Filter filter; public static final int SORTED_COLUMN_INDEX = 3; - public FilterResult(Filter filter, List rows) { + public FilterResult(Filter filter, List rows) { this.rows = new ArrayList(rows); this.filter = filter; } @@ -37,7 +41,7 @@ public class FilterResult { /** * @return a list of arrays */ - public List getRows() { + public List getRows() { return rows; } @@ -45,16 +49,16 @@ public class FilterResult { return rows.size(); } - public Integer getSnapshotId(Object row) { - return (Integer) ((Object[]) row)[getSnapshotIdIndex()]; + public Integer getSnapshotId(Object[] row) { + return (Integer) row[getSnapshotIdIndex()]; } - public Integer getProjectId(Object row) { - return (Integer) ((Object[]) row)[getProjectIdIndex()]; + public Integer getProjectId(Object[] row) { + return (Integer) row[getProjectIdIndex()]; } - public Integer getRootProjectId(Object row) { - return (Integer) ((Object[]) row)[getRootProjectIdIndex()]; + public Integer getRootProjectId(Object[] row) { + return (Integer) row[getRootProjectIdIndex()]; } public int getSnapshotIdIndex() { @@ -71,9 +75,9 @@ public class FilterResult { public void sort() { if (filter.isSorted()) { - Comparator comparator = (filter.isTextSort() ? new StringIgnoreCaseComparator(SORTED_COLUMN_INDEX) : new NumericComparator(SORTED_COLUMN_INDEX)); + Comparator comparator = (filter.isTextSort() ? new StringIgnoreCaseComparator(SORTED_COLUMN_INDEX) : new NumericComparator(SORTED_COLUMN_INDEX)); if (!filter.isAscendingSort()) { - comparator = new ReverseComparator(comparator); + comparator = Ordering.from(comparator).reverse(); } Collections.sort(rows, comparator); } @@ -98,7 +102,7 @@ public class FilterResult { } } - static final class NumericComparator implements Comparator, Serializable { + static final class NumericComparator implements Comparator, Serializable { private static final long serialVersionUID = 4627704879575964978L; private int index; @@ -106,14 +110,15 @@ public class FilterResult { this.index = index; } - public int compare(Object a1, Object a2) { - Comparable c1 = (Comparable) ((Object[]) a1)[index]; - Object o2 = ((Object[]) a2)[index]; + public int compare(Object[] a1, Object[] a2) { + Comparable c1 = (Comparable) a1[index]; + Comparable o2 = (Comparable) a2[index]; + return (c1 == null ? -1 : (o2 == null ? 1 : c1.compareTo(o2))); } } - static final class StringIgnoreCaseComparator implements Comparator, Serializable { + static final class StringIgnoreCaseComparator implements Comparator, Serializable { private static final long serialVersionUID = 963926659201833101L; private int index; @@ -121,12 +126,12 @@ public class FilterResult { this.index = index; } - public int compare(Object o1, Object o2) { - String s1 = (String)((Object[]) o1)[index]; + public int compare(Object[] o1, Object[] o2) { + String s1 = (String) o1[index]; if (s1 == null) { return -1; } - String s2 = (String)((Object[]) o2)[index]; + String s2 = (String) o2[index]; if (s2 == null) { return 1; } diff --git a/sonar-server/src/test/java/org/sonar/server/filters/FilterExecutorTest.java b/sonar-server/src/test/java/org/sonar/server/filters/FilterExecutorTest.java index c6cfe6917a5..20b6ed429ae 100644 --- a/sonar-server/src/test/java/org/sonar/server/filters/FilterExecutorTest.java +++ b/sonar-server/src/test/java/org/sonar/server/filters/FilterExecutorTest.java @@ -34,7 +34,6 @@ import java.util.Date; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; - public class FilterExecutorTest extends AbstractDbUnitTestCase { @Test @@ -345,7 +344,7 @@ public class FilterExecutorTest extends AbstractDbUnitTestCase { assertThat(result.size()).isEqualTo(snapshotIds.length); for (int snapshotId : snapshotIds) { boolean found = false; - for (Object row : result.getRows()) { + for (Object[] row : result.getRows()) { found |= result.getSnapshotId(row) == snapshotId; } if (!found) { -- 2.39.5