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