/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
@Override
public int compare(DescriptionElementBase o1, DescriptionElementBase o2) {
- return DescriptionHelper.getLabel(o1).compareTo(DescriptionHelper.getLabel(o2));
+ if (o1.equals(o2)){
+ return 0;
+ }
+ int result = DescriptionHelper.getLabel(o1).compareTo(DescriptionHelper.getLabel(o2));
+ if (result == 0){
+ return o1.getUuid().compareTo(o2.getUuid());
+ }
+ return result;
}
};
-
+
private Set<FeatureNodeContainer> featureNodeContainers = new HashSet<FeatureNodeContainer>();
-
+
private FeatureNodeContainer root;
private DescriptionBase description;
private FeatureTree featureTree;
-
+
public FeatureNodeContainerTree(DescriptionBase description, FeatureTree featureTree){
this.description = description;
this.featureTree = featureTree;
-
+
root = new FeatureNodeContainer(this);
-
+
buildTree();
}
-
+
/**
* Traverses the given {@link FeatureNode} and computes a FeatureNodeContainer branch if the
* given {@link TaxonDescription} has elements for the given feature node or any of its children
*/
public void buildTree(){
List<FeatureNode> children = featureTree.getRootChildren();
-
+
// if(description.getElements().isEmpty()){
// return;
// }
-
+
for(FeatureNode featureNode : children){
root.findLeaves(featureNode);
}
}
-
+
/**
* <p>getFeatureNodeContainerForDescriptionElement</p>
*
*/
public FeatureNodeContainer getFeatureNodeContainerForDescriptionElement (DescriptionElementBase descriptionElement) {
List<FeatureNodeContainer> leafs = root.getLeafs();
-
+
for(FeatureNodeContainer container : leafs){
if(container.getDescriptionElements().contains(descriptionElement)){
return container;
}
return null;
}
-
+
/**
* Returns all elements contained in the given {@link DescriptionBase description} that have the given {@link Feature feature}.
- *
+ *
* @param description
* @param feature
* @return a list of description elements with the given feature alphabetically sorted by {@link DescriptionHelper#getLabel(Object)}
*/
public List<DescriptionElementBase> getDescriptionsElementsForFeature(Feature feature) {
List<DescriptionElementBase> featureElements = new ArrayList<DescriptionElementBase>();
-
+
Set<DescriptionElementBase> elements = description.getElements();
-
+
if (elements != null) {
for (DescriptionElementBase element : elements) {
- Feature elementFeature = (Feature) HibernateProxyHelper.deproxy(element.getFeature());
-
+ Feature elementFeature = HibernateProxyHelper.deproxy(element.getFeature());
+
if (feature.equals(elementFeature)) {
featureElements.add(element);
}
}
}
-
+
if(featureElements.size() != 0){
Collections.sort(featureElements, comparator);
}
-
+
return featureElements;
}
-
-
- public FeatureNodeContainer getFeatureNodeContainer(Feature feature) {
+
+
+ public FeatureNodeContainer getFeatureNodeContainer(Feature feature) {
List<FeatureNodeContainer> leafs = root.getLeafs();
-
+
for(FeatureNodeContainer container : leafs){
if(container.getFeature().equals(feature)){
return container;
}
return null;
}
-
+
public FeatureNodeContainer getFeatureNodeContainer(FeatureNode featureNode){
List<FeatureNodeContainer> leafs = root.getLeafs();
-
+
for(FeatureNodeContainer container : leafs){
if(container.getFeatureNode().equals(featureNode)){
return container;
}
return null;
}
-
+
public void addContainer(FeatureNodeContainer container){
featureNodeContainers.add(container);
}
/**
- *
+ *
*/
public void removeContainer(FeatureNodeContainer container) {
featureNodeContainers.remove(container);
}
-
+
public FeatureNodeContainer getRoot() {
return root;
}
public FeatureTree getFeatureTree() {
return featureTree;
}
-
+
}