diff options
Diffstat (limited to 'main/src/cgeo/geocaching/files/SimpleDirChooser.java')
| -rw-r--r-- | main/src/cgeo/geocaching/files/SimpleDirChooser.java | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/main/src/cgeo/geocaching/files/SimpleDirChooser.java b/main/src/cgeo/geocaching/files/SimpleDirChooser.java index 3f6182c..3e09cc4 100644 --- a/main/src/cgeo/geocaching/files/SimpleDirChooser.java +++ b/main/src/cgeo/geocaching/files/SimpleDirChooser.java @@ -29,6 +29,7 @@ import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; /** @@ -141,7 +142,7 @@ public class SimpleDirChooser extends AbstractListActivity { } } catch (RuntimeException e) { } - Collections.sort(listDirs); + Collections.sort(listDirs, Option.NAME_COMPARATOR); if (dir.getParent() != null) { listDirs.add(0, new Option(PARENT_DIR, dir.getParent(), false)); } @@ -247,15 +248,21 @@ public class SimpleDirChooser extends AbstractListActivity { } } - /** - * Note: this class has a natural ordering that is inconsistent with equals. - */ - public static class Option implements Comparable<Option> { + public static class Option { private final String name; private final String path; private boolean checked = false; private boolean writeable = false; + private static Comparator<Option> NAME_COMPARATOR = new Comparator<SimpleDirChooser.Option>() { + + @Override + public int compare(Option lhs, Option rhs) { + return String.CASE_INSENSITIVE_ORDER.compare(lhs.name, rhs.name); + } + + }; + public Option(String name, String path, boolean writeable) { this.name = name; this.path = path; @@ -281,14 +288,6 @@ public class SimpleDirChooser extends AbstractListActivity { public boolean isWriteable() { return writeable; } - - @Override - public int compareTo(Option other) { - if (other != null && this.name != null) { - return String.CASE_INSENSITIVE_ORDER.compare(this.name, other.getName()); - } - throw new IllegalArgumentException(""); - } } public static class DirOnlyFilenameFilter implements FilenameFilter { |
