X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FBasicLibrary.java;h=b3b49fdbce50ec5aa6b4877af9c42b2a949e39df;hb=c1b93db3213970c86b766c92a0b0d546c9d1c2ae;hp=5898ac492c626a7fbc55da65072c3eaf0c202a3d;hpb=c8d48938ca540d7b619a2c19bd76623d689b72cb;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/library/BasicLibrary.java b/src/be/nikiroo/fanfix/library/BasicLibrary.java index 5898ac4..b3b49fd 100644 --- a/src/be/nikiroo/fanfix/library/BasicLibrary.java +++ b/src/be/nikiroo/fanfix/library/BasicLibrary.java @@ -8,7 +8,9 @@ import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.TreeMap; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; @@ -246,6 +248,47 @@ abstract public class BasicLibrary { return list; } + /** + * List all the known types (sources) of stories, grouped by directory + * ("Source_1/a" and "Source_1/b" will be grouped into "Source_1"). + *

+ * Note that an empty item in the list means a non-grouped source (type) -- + * e.g., you could have for Source_1: + *

+ * + * @return the grouped list + */ + public synchronized Map> getSourcesGrouped() { + Map> map = new TreeMap>(); + for (String source : getSources()) { + String name; + String subname; + + int pos = source.indexOf('/'); + if (pos > 0 && pos < source.length() - 1) { + name = source.substring(0, pos); + subname = source.substring(pos + 1); + + } else { + name = source; + subname = ""; + } + + List list = map.get(name); + if (list == null) { + list = new ArrayList(); + map.put(name, list); + } + list.add(subname); + } + + return map; + } + /** * List all the known authors of stories. * @@ -375,7 +418,7 @@ abstract public class BasicLibrary { /** * List all the stories in the {@link BasicLibrary}. *

- * Cover images not included. + * Cover images MAYBE not included. * * @return the stories */