From 3d1f57c14e9eaa54d54b758951e3188c93265e4f Mon Sep 17 00:00:00 2001 From: Jamie Doornbos Date: Wed, 6 Jul 2011 19:09:41 +0000 Subject: [PATCH] Extend import grouping functionality to allow groups to be specified. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6676 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/tools/ImportSet.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/threerings/presents/tools/ImportSet.java b/src/main/java/com/threerings/presents/tools/ImportSet.java index 46523b48f..04ba2aa7a 100644 --- a/src/main/java/com/threerings/presents/tools/ImportSet.java +++ b/src/main/java/com/threerings/presents/tools/ImportSet.java @@ -327,12 +327,21 @@ public class ImportSet * ordering and spacing. Within each group, sorting is alphabetical. */ public List> toGroups () + { + return toGroups(IMPORT_GROUPS); + } + + /** + * Converts the set of imports to groups of class names, according to the provided groups. + * Within each group, sorting is alphabetical. + */ + public List> toGroups (final List groups) { List list = Lists.newArrayList(_imports); Collections.sort(list, new Comparator() { public int compare (String class1, String class2) { return ComparisonChain.start() - .compare(findImportGroup(class1), findImportGroup(class2)) + .compare(findImportGroup(class1, groups), findImportGroup(class2, groups)) .compare(class1, class2) .result(); } @@ -341,7 +350,7 @@ public class ImportSet List current = null; int lastGroup = -1; for (String imp : list) { - int group = findImportGroup(imp); + int group = findImportGroup(imp, groups); if (group != lastGroup) { if (current == null || !current.isEmpty()) { result.add(current = Lists.newArrayList()); @@ -401,10 +410,10 @@ public class ImportSet return Pattern.compile(pattern.toString()); } - protected static int findImportGroup (String imp) + protected static int findImportGroup (String imp, List groups) { String longest = null; - for (String prefix : IMPORT_GROUPS) { + for (String prefix : groups) { if (!imp.startsWith(prefix)) { continue; } @@ -412,7 +421,7 @@ public class ImportSet longest = prefix; } } - return IMPORT_GROUPS.indexOf(longest); + return groups.indexOf(longest); } protected HashSet _imports = Sets.newHashSet();