I'd just write a method that did what you describe... something like:
public static <T> void sortWIthDefault(final List<T> list)
{
Collections.sort(list);
// remove the default item
// insert the default item at the start of the list
}
You could also make use of a comparator (it would be less obvious though) where it always compares the default item as the lowest in any comparison and the natural comparison for the rest of the items. For that you would call Collections.sort(List, Comparator);
Here is some code for such a Comparator... again. I don't really like it because it isn't obvious... but it is a reasonable solution I guess:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Main
{
public static void main(final String[] argv)
{
final List<Integer> list;
list = new ArrayList<Integer>();
for(int i = 10; i > 0; i--)
{
list.add(i);
}
Collections.sort(list, new DefaultAtStartComparator<Integer>(5));
System.out.println(list);
}
}
class DefaultAtStartComparator<T extends Comparable>
implements Comparator<T>
{
private final T defaultValue;
public DefaultAtStartComparator(final T value)
{
defaultValue = value;
}
public int compare(final T a,
final T b)
{
if(a.equals(defaultValue))
{
return (-1);
}
if(b.equals(defaultValue))
{
return (1);
}
return (a.compareTo(b));
}
}