Project

General

Profile

Download (4.16 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 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.service.dto;
10

    
11
import java.util.ArrayList;
12
import java.util.Collections;
13
import java.util.Comparator;
14
import java.util.List;
15

    
16
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
17

    
18
/**
19
 * @author a.kohlbecker
20
 \* @since Jun 25, 2015
21
 *
22
 */
23
public class CondensedDistribution {
24

    
25
    private List<DistributionItem> indigenous = new ArrayList<DistributionItem>();
26
    private List<DistributionItem> foreign = new ArrayList<DistributionItem>();
27

    
28
    /**
29
     * @return the foreign
30
     */
31
    public List<DistributionItem> getForeign() {
32
        return foreign;
33
    }
34

    
35
    /**
36
     * @param foreign the foreign to set
37
     */
38
    public void setForeign(List<DistributionItem> foreign) {
39
        this.foreign = foreign;
40
    }
41

    
42
    /**
43
     * @param indigenous the indigenous to set
44
     */
45
    public void setIndigenous(List<DistributionItem> indigenous) {
46
        this.indigenous = indigenous;
47
    }
48

    
49
    /**
50
     * @return the indigenous
51
     */
52
    public List<DistributionItem> getIndigenous() {
53
        return indigenous;
54
    }
55

    
56
    public void addForeignDistributionItem(PresenceAbsenceTerm status, String areaStatusLabel, String sortString) {
57
        foreign.add(new DistributionItem(status, areaStatusLabel, sortString));
58
    }
59

    
60
    public void addIndigenousDistributionItem(PresenceAbsenceTerm status, String areaStatusLabel, String sortString) {
61
        indigenous.add(new DistributionItem(status, areaStatusLabel, sortString));
62
    }
63

    
64

    
65
    public void sortForeign() {
66
        Collections.sort(foreign, new CondensedDistributionComparator());
67
    }
68

    
69
    public void sortIndigenous() {
70
        Collections.sort(indigenous, new CondensedDistributionComparator());
71
    }
72

    
73
    @Override
74
    public String toString() {
75

    
76
        StringBuilder out = new StringBuilder();
77

    
78
        boolean isFirst = true;
79
        for(DistributionItem item : indigenous) {
80
            if(!isFirst) {
81
                out.append(" ");
82
            }
83
            out.append(item.areaStatusLabel);
84
            isFirst = false;
85
        }
86

    
87
        if(!isFirst) {
88
            out.append(" ");
89
        }
90
        isFirst = true;
91
        if(!foreign.isEmpty()) {
92
            out.append("[");
93
            for(DistributionItem item : foreign) {
94
                if(!isFirst) {
95
                    out.append(" ");
96
                }
97
                out.append(item.areaStatusLabel);
98
                isFirst = false;
99
            }
100
            out.append("]");
101
        }
102
        return out.toString();
103
    }
104

    
105
    public class DistributionItem {
106

    
107

    
108
        private PresenceAbsenceTerm status;
109
        private String areaStatusLabel;
110
        private final String sortString;
111

    
112
        /**
113
         * @param status
114
         * @param areaStatusLabel
115
         */
116
        public DistributionItem(PresenceAbsenceTerm status, String areaStatusLabel, String sortString) {
117
            this.status = status;
118
            this.areaStatusLabel = areaStatusLabel;
119
            this.sortString = sortString;
120
        }
121
        /**
122
         * @return the status
123
         */
124
        public PresenceAbsenceTerm getStatus() {
125
            return status;
126
        }
127

    
128
        /**
129
         * @return the areaStatusLabel
130
         */
131
        public String getAreaStatusLabel() {
132
            return areaStatusLabel;
133
        }
134

    
135
        /**
136
         * @param status the status to set
137
         */
138
        public void setStatus(PresenceAbsenceTerm status) {
139
            this.status = status;
140
        }
141
        /**
142
         * @param areaStatusLabel the areaStatusLabel to set
143
         */
144
        public void setAreaStatusLabel(String areaStatusLabel) {
145
            this.areaStatusLabel = areaStatusLabel;
146
        }
147
    }
148

    
149
    class CondensedDistributionComparator implements Comparator<DistributionItem>{
150

    
151
        /**
152
         * {@inheritDoc}
153
         */
154
        @Override
155
        public int compare(DistributionItem o1, DistributionItem o2) {
156
            return o1.sortString.compareToIgnoreCase(o2.sortString);
157
        }
158

    
159

    
160

    
161
    }
162
}
(2-2/20)