search cli: code cleanup
[fanfix.git] / src / be / nikiroo / fanfix / searchable / BasicSearchable.java
index 0449b818caa9ec88f9557acaa67460bfce084382..d8076fa7a1b87f99e452cddcef30100305884c7b 100644 (file)
@@ -34,6 +34,38 @@ public abstract class BasicSearchable {
                support = BasicSupport.getSupport(getType(), null);
        }
 
+       /**
+        * Find the given tag by its hierarchical IDs.
+        * <p>
+        * I.E., it will take the tag A, subtag B, subsubtag C...
+        * 
+        * @param ids
+        *            the IDs to look for
+        * 
+        * @return the appropriate tag fully filled, or NULL if not found
+        * 
+        * @throws IOException
+        *             in case of I/O error
+        */
+       public SearchableTag getTag(Integer... ids) throws IOException {
+               SearchableTag tag = null;
+               List<SearchableTag> tags = getTags();
+
+               for (Integer tagIndex : ids) {
+                       // ! 1-based index !
+                       if (tagIndex == null || tags == null || tagIndex <= 0
+                                       || tagIndex > tags.size()) {
+                               return null;
+                       }
+
+                       tag = tags.get(tagIndex - 1);
+                       fillTag(tag);
+                       tags = tag.getChildren();
+               }
+
+               return tag;
+       }
+
        /**
         * The support type.
         * 
@@ -189,7 +221,7 @@ public abstract class BasicSearchable {
         * 
         * @return an implementation that supports it, or NULL
         */
-       public static BasicSearchable getSearchable(SupportType type) {
+       static public BasicSearchable getSearchable(SupportType type) {
                BasicSearchable support = null;
 
                switch (type) {