*/
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<Object[]> rows;
private Filter filter;
public static final int SORTED_COLUMN_INDEX = 3;
- public FilterResult(Filter filter, List rows) {
+ public FilterResult(Filter filter, List<Object[]> rows) {
this.rows = new ArrayList<Object[]>(rows);
this.filter = filter;
}
/**
* @return a list of arrays
*/
- public List getRows() {
+ public List<Object[]> getRows() {
return rows;
}
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() {
public void sort() {
if (filter.isSorted()) {
- Comparator comparator = (filter.isTextSort() ? new StringIgnoreCaseComparator(SORTED_COLUMN_INDEX) : new NumericComparator(SORTED_COLUMN_INDEX));
+ Comparator<Object[]> 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);
}
}
}
- static final class NumericComparator implements Comparator, Serializable {
+ static final class NumericComparator implements Comparator<Object[]>, Serializable {
private static final long serialVersionUID = 4627704879575964978L;
private int index;
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<Object[]>, Serializable {
private static final long serialVersionUID = 963926659201833101L;
private int index;
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;
}