+ if (prefix != null && !prefix.isEmpty()) {
+ try {
+ // We found a prefix, so everything should be sortable
+ SortedMap<Double, Entry<String, URL>> map = new TreeMap<Double, Entry<String, URL>>();
+ for (Entry<String, URL> entry : urls) {
+ String num = entry.getKey().substring(prefix.length() + 1)
+ .trim();
+ String name = "";
+ int pos = num.indexOf(' ');
+ if (pos >= 0) {
+ name = num.substring(pos).trim();
+ num = num.substring(0, pos).trim();
+ }
+
+ if (!name.isEmpty()) {
+ name = "Tome " + num + ": " + name;
+ } else {
+ name = "Tome " + num;
+ }
+
+ double key = Double.parseDouble(num);
+
+ map.put(key, new AbstractMap.SimpleEntry<String, URL>(name,
+ entry.getValue()));
+ }
+ urls = new ArrayList<Entry<String, URL>>(map.values());
+ } catch (NumberFormatException e) {
+ Instance.getTraceHandler()
+ .error(new IOException(
+ "Cannot find a tome number, revert to default sorting",
+ e));
+ // by default, the chapters are in reversed order
+ Collections.reverse(urls);
+ }
+ } else {
+ // by default, the chapters are in reversed order
+ Collections.reverse(urls);
+ }