Revision 4dccf2d6
Added by Andreas Müller about 3 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/PresenceAbsenceTerm.java | ||
---|---|---|
30 | 30 |
import org.apache.log4j.Logger; |
31 | 31 |
import org.hibernate.envers.Audited; |
32 | 32 |
|
33 |
import eu.etaxonomy.cdm.model.common.CdmBase;
|
|
33 |
import eu.etaxonomy.cdm.common.CdmUtils;
|
|
34 | 34 |
import eu.etaxonomy.cdm.model.common.Language; |
35 | 35 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
36 | 36 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
... | ... | |
655 | 655 |
} |
656 | 656 |
|
657 | 657 |
/** |
658 |
* Compares this OrderedTermBase with the specified OrderedTermBase for |
|
659 |
* order. Returns a -1, 0, or +1 if the orderId of this object is greater |
|
660 |
* than, equal to, or less than the specified object. |
|
661 |
* <p> |
|
662 |
* <b>Note:</b> The compare logic of this method is the <b>inverse logic</b> |
|
663 |
* of the the one implemented in |
|
664 |
* {@link java.lang.Comparable#compareTo(java.lang.Object)} |
|
665 |
* |
|
666 |
* @param orderedTerm |
|
667 |
* the OrderedTermBase to be compared |
|
668 |
* @param skipVocabularyCheck |
|
669 |
* whether to skip checking if both terms to compare are in the |
|
670 |
* same vocabulary |
|
671 |
* @throws NullPointerException |
|
672 |
* if the specified object is null |
|
658 |
* Includes presence/absence compare instead of pure uuid compare |
|
673 | 659 |
*/ |
674 | 660 |
@Override |
675 |
protected int performCompareTo(PresenceAbsenceTerm presenceAbsenceTerm, boolean skipVocabularyCheck) { |
|
676 |
|
|
677 |
PresenceAbsenceTerm presenceAbsenceTermLocal = CdmBase.deproxy(presenceAbsenceTerm); |
|
678 |
if(! skipVocabularyCheck){ |
|
679 |
if (this.vocabulary == null || presenceAbsenceTermLocal.vocabulary == null){ |
|
680 |
throw new IllegalStateException("An ordered term (" + this.toString() + " or " + |
|
681 |
presenceAbsenceTermLocal.toString() + ") of class " + this.getClass() + " or " + |
|
682 |
presenceAbsenceTermLocal.getClass() + " does not belong to a vocabulary and therefore " |
|
683 |
+ "can not be compared"); |
|
684 |
} |
|
685 |
if (presenceAbsenceTermLocal.isAbsenceTerm() != this.isAbsenceTerm() ){ |
|
686 |
if (presenceAbsenceTermLocal.isAbsenceTerm()){ |
|
687 |
return 1; |
|
688 |
}else{ |
|
689 |
return -1; |
|
690 |
} |
|
691 |
|
|
661 |
protected int compareVocabularies(PresenceAbsenceTerm thatTerm) { |
|
662 |
UUID thisVocUuid = this.vocabulary == null? null:this.vocabulary.getUuid(); |
|
663 |
UUID thatVocUuid = thatTerm.getVocabulary() == null? null:thatTerm.getVocabulary().getUuid(); |
|
664 |
int vocCompare = CdmUtils.nullSafeCompareTo(thisVocUuid, thatVocUuid); |
|
665 |
if (vocCompare != 0 && thatTerm.isAbsenceTerm() != this.isAbsenceTerm() ){ |
|
666 |
if (thatTerm.isAbsenceTerm()){ |
|
667 |
return 1; |
|
668 |
}else{ |
|
669 |
return -1; |
|
692 | 670 |
} |
693 | 671 |
} |
672 |
return vocCompare; |
|
673 |
} |
|
694 | 674 |
|
695 |
int orderThat; |
|
696 |
int orderThis; |
|
697 |
try { |
|
698 |
orderThat = presenceAbsenceTermLocal.orderIndex;//OLD: this.getVocabulary().getTerms().indexOf(orderedTerm); |
|
699 |
orderThis = orderIndex; //OLD: this.getVocabulary().getTerms().indexOf(this); |
|
700 |
} catch (RuntimeException e) { |
|
701 |
throw e; |
|
702 |
} |
|
703 |
if (orderThis > orderThat){ |
|
704 |
return -1; |
|
705 |
}else if (orderThis < orderThat){ |
|
706 |
return 1; |
|
707 |
}else { |
|
708 |
return 0; |
|
709 |
} |
|
675 |
/** |
|
676 |
* {@inheritDoc} |
|
677 |
* |
|
678 |
* For {@link PresenceAbsenceTerm} there is an additional rule that before comparing vocabulary uuid |
|
679 |
* presence terms are preferred to absence terms. |
|
680 |
*/ |
|
681 |
@Override |
|
682 |
public int compareTo(PresenceAbsenceTerm presenceAbsenceTerm) { |
|
683 |
return performCompareTo(presenceAbsenceTerm, true); |
|
710 | 684 |
} |
711 | 685 |
|
712 | 686 |
public boolean isAbsenceTerm() { |
Also available in: Unified diff
fix #8858 Improve presence/absence handling for PresenceAbsenceTerm.compareTo