1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2016 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.api.utility;
|
11
|
|
12
|
import java.util.Comparator;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import eu.etaxonomy.cdm.api.service.DistributionNodeByAreaLabelComparator;
|
16
|
import eu.etaxonomy.cdm.common.TreeNode;
|
17
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
18
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
19
|
|
20
|
/**
|
21
|
* Enumeration that defines the ordering method for distribution trees.
|
22
|
*
|
23
|
* @author a.mueller
|
24
|
* @date 04.04.2016
|
25
|
*
|
26
|
*/
|
27
|
public enum DistributionOrder {
|
28
|
LABEL,
|
29
|
AREA_ORDER;
|
30
|
|
31
|
/**
|
32
|
* Returns a comparator that implements the given distribution order.
|
33
|
* @return
|
34
|
*/
|
35
|
public Comparator<TreeNode<Set<Distribution>, NamedArea>> getComparator() {
|
36
|
if (this == LABEL){
|
37
|
return new DistributionNodeByAreaLabelComparator();
|
38
|
}else if (this == AREA_ORDER){
|
39
|
return new DistributionNodeByAreaOrderComparator();
|
40
|
}else{
|
41
|
throw new IllegalStateException("Comparator is not available for DistributionOrder '" + this.name() + "'");
|
42
|
}
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* The default distribution order. Currently this is {@link DistributionOrder#LABEL}
|
47
|
* @return the default distribution order.
|
48
|
*/
|
49
|
public static DistributionOrder getDefault() {
|
50
|
return LABEL;
|
51
|
}
|
52
|
}
|