diff options
author | James Moger <james.moger@gitblit.com> | 2011-10-02 16:59:44 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-10-02 16:59:44 -0400 |
commit | f762b160efd5cafd919a6fd7f9587f578eceb454 (patch) | |
tree | 5d43db6ca7bd5768abdc2064483fb427f41be28d /src/com/gitblit/utils/StringUtils.java | |
parent | 19c634873b49dea8b49fc54ca393153f7eb0eb35 (diff) | |
parent | 10177fb0a59cc9fc61fb78c724f7b0816b69b798 (diff) | |
download | gitblit-f762b160efd5cafd919a6fd7f9587f578eceb454.tar.gz gitblit-f762b160efd5cafd919a6fd7f9587f578eceb454.zip |
Merge branch 'master' into rpc
Diffstat (limited to 'src/com/gitblit/utils/StringUtils.java')
-rw-r--r-- | src/com/gitblit/utils/StringUtils.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/com/gitblit/utils/StringUtils.java b/src/com/gitblit/utils/StringUtils.java index 77d3cbbc..f4e9256f 100644 --- a/src/com/gitblit/utils/StringUtils.java +++ b/src/com/gitblit/utils/StringUtils.java @@ -19,6 +19,8 @@ import java.io.UnsupportedEncodingException; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.regex.PatternSyntaxException;
@@ -395,4 +397,44 @@ public class StringUtils { }
return false;
}
+
+ /**
+ * Compare two repository names for proper group sorting.
+ *
+ * @param r1
+ * @param r2
+ * @return
+ */
+ public static int compareRepositoryNames(String r1, String r2) {
+ // sort root repositories first, alphabetically
+ // then sort grouped repositories, alphabetically
+ int s1 = r1.indexOf('/');
+ int s2 = r2.indexOf('/');
+ if (s1 == -1 && s2 == -1) {
+ // neither grouped
+ return r1.compareTo(r2);
+ } else if (s1 > -1 && s2 > -1) {
+ // both grouped
+ return r1.compareTo(r2);
+ } else if (s1 == -1) {
+ return -1;
+ } else if (s2 == -1) {
+ return 1;
+ }
+ return 0;
+ }
+
+ /**
+ * Sort grouped repository names.
+ *
+ * @param list
+ */
+ public static void sortRepositorynames(List<String> list) {
+ Collections.sort(list, new Comparator<String>() {
+ @Override
+ public int compare(String o1, String o2) {
+ return compareRepositoryNames(o1, o2);
+ }
+ });
+ }
}
|