2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.e4
;
11 import java
.util
.Comparator
;
13 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonDistributionDTO
;
14 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
15 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDtoByNameComparator
;
16 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDtoByRankAndNameComparator
;
22 public class TaxonDistributionDtoComparator
implements Comparator
<TaxonDistributionDTO
> {
24 Comparator
<TaxonNodeDto
> comparator1
= new TaxonNodeDtoByRankAndNameComparator();
25 Comparator
<TaxonNodeDto
> comparator2
= new TaxonNodeDtoByNameComparator();
27 public TaxonDistributionDtoComparator(){
32 public int compare(TaxonDistributionDTO taxonDistr0
, TaxonDistributionDTO taxonDistr1
) {
34 //if parent is not the same sort by name
35 if ((taxonDistr0
.getTaxonNodeDto() != null && taxonDistr1
.getTaxonNodeDto() != null) && !taxonDistr0
.getTaxonNodeDto().getParentUUID().equals(taxonDistr1
.getTaxonNodeDto().getParentUUID()) ){
36 return comparator2
.compare(taxonDistr0
.getTaxonNodeDto(), taxonDistr1
.getTaxonNodeDto());
38 // if parent is the same sort by rank and name
39 if (taxonDistr0
.getTaxonNodeDto() != null && taxonDistr1
.getTaxonNodeDto() != null && taxonDistr0
.getTaxonNodeDto().getParentUUID().equals( taxonDistr1
.getTaxonNodeDto().getParentUUID())){
40 return this.comparator1
.compare(taxonDistr0
.getTaxonNodeDto(), taxonDistr1
.getTaxonNodeDto());
41 }else if (taxonDistr0
== taxonDistr1
|| (taxonDistr0
.getTaxonNodeDto() == null) && (taxonDistr1
.getTaxonNodeDto() == null)){
43 } else if (taxonDistr0
.getTaxonNodeDto() != null && taxonDistr1
.getTaxonNodeDto() == null){
45 } else if (taxonDistr0
.getTaxonNodeDto() == null && taxonDistr1
.getTaxonNodeDto() != null){
48 return taxonDistr0
.getTaxonUuid().compareTo(taxonDistr1
.getTaxonUuid());