From: Patric Plitzner Date: Wed, 30 Oct 2013 14:24:36 +0000 (+0000) Subject: - added test code (in comments) X-Git-Tag: 3.6.0~904 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/b5f27c167ea33378a8ef169701be86f6a20bc5b3 - added test code (in comments) --- diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java index b40d34932..ec74879c8 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java @@ -924,6 +924,7 @@ public abstract class AbstractUtility { } } + /** * Orders a Collection of {@link IEnumTerm}s according to the term * hierarchy. The hierarchy will be reduced to two layers: one layer being @@ -1007,4 +1008,126 @@ public abstract class AbstractUtility { } } + +// /** +// * Orders a Collection of {@link IEnumTerm}s according to the term +// * hierarchy. The hierarchy will be reduced to two layers: one layer being +// * the root elements (that have no parents) and the other being their +// * children and children's children recursively.
+// * The returned map will be be ordered primarily by root elements and +// * secondarily by the child elements, both ascending alphabetically.
+// *
+// * The reduced hierarchy could look like this:
+// * +// * +// * @param terms +// * A {@link Collection} of {@link IEnumTerm}s for which the term +// * hierarchy should be created +// * @return a map which holds the terms as keys and their string +// * representation via {@link IEnumTerm#getMessage()} as values +// */ +// public static > LinkedHashMap orderTerms(Collection terms) { +// Comparator> comparator = new Comparator>() { +// @Override +// public int compare(TermNode t1, TermNode t2) { +// return t1.getTerm().getMessage().compareTo(t2.getTerm().getMessage()); +// } +// }; +// TreeSet> parentElements = new TreeSet>(comparator); +// for(T term : terms) { +// Set childList = new TreeSet(comparator); +// // add root element as keys +// if(term.getKindOf()==null){ +// parentElements.add(new TermNode(term)); +// } +// // add child element to parent +// else{ +// T parent = getParentFor(term); +// if(termHierarchy.containsKey(parent)){ +// termHierarchy.get(parent).add(term); +// } +// else{ +// childList.add(term); +// termHierarchy.put(parent, childList); +// } +// } +// } +// +// // create list according to the type hierarchy (root elements alphabetically with recursive children also alphabetically) +// LinkedHashMap result = new LinkedHashMap(); +// for(Entry> entry:termHierarchy.entrySet()){ +// T root = entry.getKey(); +// result.put(root, root.getMessage()); +// for(T child:entry.getValue()){ +// result.put(child, " " + child.getMessage()); +// } +// } +// return result; +// } +// +// private static addToParents(TreeSet> parents, Collection terms){ +// for(T term:terms){ +// +// } +// } +// +// @SuppressWarnings("unchecked") +// /** +// * Recursively iterates over all term parents until no more parent is found i.e. the root node +// * @param term The term for which the parent should be found +// * @return the root terms of the term hierarchy +// */ +// private static> T getParentFor(T term){ +// // PP: cast should be safe. Why is Eclipse complaining?? +// T parent = (T) term.getKindOf(); +// if(parent==null){ +// return term; +// } +// else{ +// return getParentFor((T) term.getKindOf()); +// } +// } +// +// private class TermNode{ +// private final T term; +// private final TreeSet> children; +// +// /** +// * @param term +// * @param children +// */ +// public TermNode(T term) { +// super(); +// this.term = term; +// this.children = new TreeSet>(); +// } +// +// public void addChild(TermNode child){ +// this.children.add(child); +// } +// +// /** +// * @return the children +// */ +// public TreeSet> getChildren() { +// return children; +// } +// +// /** +// * @return the term +// */ +// public T getTerm() { +// return term; +// } +// } + }