Skip to content

Commit

Permalink
format & import cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian committed Jan 4, 2012
1 parent a3c69dc commit 03d66bd
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions flaptor-util/com/flaptor/util/CollectionsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

package com.flaptor.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedSet;
Expand Down Expand Up @@ -57,11 +55,11 @@ public int compare(T o1, T o2) {
}

public static <T> Comparator<T> inverseComparator(final Comparator<T> comp) {
return new Comparator<T>() {
public int compare(T o1, T o2) {
return comp.compare(o2, o1);
}
};
return new Comparator<T>() {
public int compare(T o1, T o2) {
return comp.compare(o2, o1);
}
};
}

public static <T extends Comparable<T>> Iterable<T> mergeIterables(final Iterable<? extends Iterable<? extends T>> iterables) {
Expand Down Expand Up @@ -329,19 +327,21 @@ public static float[] toFloatArray(String... strings) {
return floats;
}

public static <T extends Comparable<T>> SortedSet<T> sortTopN(Iterable<T> iterable, int n) {
return sortTopN(iterable, n, Ordering.<T>natural());
public static <T extends Comparable<T>> SortedSet<T> sortTopN(
Iterable<T> iterable, int n) {
return sortTopN(iterable, n, Ordering.<T> natural());
}
public static <T> SortedSet<T> sortTopN(Iterable<T> iterable, int n, Comparator<T> comparator) {
TreeSet<T> r = Sets.newTreeSet(comparator);
for (T t : iterable) {
r.add(t);
if (r.size() > n) {
r.pollLast();
}
}
return r;

public static <T> SortedSet<T> sortTopN(Iterable<T> iterable, int n,
Comparator<T> comparator) {
TreeSet<T> r = Sets.newTreeSet(comparator);
for (T t : iterable) {
r.add(t);
if (r.size() > n) {
r.pollLast();
}
}
return r;
}

}

0 comments on commit 03d66bd

Please sign in to comment.