3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.api
.service
.dto
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Collections
;
14 import java
.util
.Comparator
;
15 import java
.util
.List
;
17 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
20 * @author a.kohlbecker
24 public class CondensedDistribution
{
26 private List
<DistributionItem
> indigenous
= new ArrayList
<DistributionItem
>();
27 private List
<DistributionItem
> foreign
= new ArrayList
<DistributionItem
>();
32 public List
<DistributionItem
> getForeign() {
37 * @param foreign the foreign to set
39 public void setForeign(List
<DistributionItem
> foreign
) {
40 this.foreign
= foreign
;
44 * @param indigenous the indigenous to set
46 public void setIndigenous(List
<DistributionItem
> indigenous
) {
47 this.indigenous
= indigenous
;
51 * @return the indigenous
53 public List
<DistributionItem
> getIndigenous() {
57 public void addForeignDistributionItem(PresenceAbsenceTerm status
, String areaStatusLabel
, String sortString
) {
58 foreign
.add(new DistributionItem(status
, areaStatusLabel
, sortString
));
61 public void addIndigenousDistributionItem(PresenceAbsenceTerm status
, String areaStatusLabel
, String sortString
) {
62 indigenous
.add(new DistributionItem(status
, areaStatusLabel
, sortString
));
66 public void sortForeign() {
67 Collections
.sort(foreign
, new CondensedDistributionComparator());
70 public void sortIndigenous() {
71 Collections
.sort(indigenous
, new CondensedDistributionComparator());
75 public String
toString() {
77 StringBuilder out
= new StringBuilder();
79 boolean isFirst
= true;
80 for(DistributionItem item
: indigenous
) {
84 out
.append(item
.areaStatusLabel
);
92 if(!foreign
.isEmpty()) {
94 for(DistributionItem item
: foreign
) {
98 out
.append(item
.areaStatusLabel
);
103 return out
.toString();
106 public class DistributionItem
{
109 private PresenceAbsenceTerm status
;
110 private String areaStatusLabel
;
111 private final String sortString
;
115 * @param areaStatusLabel
117 public DistributionItem(PresenceAbsenceTerm status
, String areaStatusLabel
, String sortString
) {
118 this.status
= status
;
119 this.areaStatusLabel
= areaStatusLabel
;
120 this.sortString
= sortString
;
125 public PresenceAbsenceTerm
getStatus() {
130 * @return the areaStatusLabel
132 public String
getAreaStatusLabel() {
133 return areaStatusLabel
;
137 * @param status the status to set
139 public void setStatus(PresenceAbsenceTerm status
) {
140 this.status
= status
;
143 * @param areaStatusLabel the areaStatusLabel to set
145 public void setAreaStatusLabel(String areaStatusLabel
) {
146 this.areaStatusLabel
= areaStatusLabel
;
150 class CondensedDistributionComparator
implements Comparator
<DistributionItem
>{
156 public int compare(DistributionItem o1
, DistributionItem o2
) {
157 return o1
.sortString
.compareToIgnoreCase(o2
.sortString
);