Project

General

Profile

Download (1.5 KB) Statistics
| Branch: | Tag: | Revision:
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.util;
10

    
11
import java.util.Comparator;
12
import java.util.Set;
13

    
14
import eu.etaxonomy.cdm.common.TreeNode;
15
import eu.etaxonomy.cdm.compare.description.DistributionNodeByAreaLabelComparator;
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
public enum DistributionOrder {
26
    LABEL,
27
    AREA_ORDER;
28

    
29
    /**
30
     * Returns a comparator that implements the given distribution order.
31
     * @return
32
     */
33
    public Comparator<TreeNode<Set<Distribution>, NamedArea>> getComparator() {
34
        if (this == LABEL){
35
            return new DistributionNodeByAreaLabelComparator();
36
        }else if (this == AREA_ORDER){
37
            return new DistributionNodeByAreaOrderComparator();
38
        }else{
39
            throw new IllegalStateException("Comparator is not available for DistributionOrder '" + this.name() + "'");
40
        }
41
    }
42

    
43
    /**
44
     * The default distribution order. Currently this is {@link DistributionOrder#LABEL}
45
     * @return the default distribution order.
46
     */
47
    public static DistributionOrder getDefault() {
48
        return LABEL;
49
    }
50
}
(7-7/15)