// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
//
// Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/forester
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
package org.forester.phylogeny.data;
import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
import org.forester.util.ForesterUtil;
+import org.forester.util.TaxonomyUtil;
public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonomy> {
public boolean isEmpty() {
return ( ( getIdentifier() == null ) && ForesterUtil.isEmpty( getTaxonomyCode() )
&& ForesterUtil.isEmpty( getCommonName() ) && ForesterUtil.isEmpty( getScientificName() )
- && ForesterUtil.isEmpty( getRank() ) && ForesterUtil.isEmpty( _uris )
- && ForesterUtil.isEmpty( getAuthority() ) && ForesterUtil.isEmpty( _synonyms ) && ForesterUtil
- .isEmpty( _lineage ) );
+ && ForesterUtil.isEmpty( _lineage ) );
}
/**
- *
+ *
* If this and taxonomy 'data' has an identifier, comparison will be based on that.
* Otherwise, if this and taxonomy 'data' has a code, comparison will be based on that.
* Otherwise, if Taxonomy 'data' has a scientific name, comparison will be
* Otherwise, if Taxonomy 'data' has a common name, comparison will be
* based on that (case insensitive!).
* (Note. This is important and should not be change without a very good reason.)
- *
+ *
*/
@Override
public boolean isEqual( final PhylogenyData data ) {
else if ( !ForesterUtil.isEmpty( getCommonName() ) && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
return getCommonName().equalsIgnoreCase( tax.getCommonName() );
}
- else if ( !ForesterUtil.isEmpty( getScientificName() ) && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
- return getScientificName().equalsIgnoreCase( tax.getCommonName() );
- }
- else if ( !ForesterUtil.isEmpty( getCommonName() ) && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
- return getCommonName().equalsIgnoreCase( tax.getScientificName() );
- }
- throw new RuntimeException( "comparison not possible with empty fields" );
+ //throw new RuntimeException( "comparison not possible with empty fields" );
+ return false;
}
public void setAuthority( final String authority ) {
}
public void setRank( final String rank ) throws PhyloXmlDataFormatException {
- if ( !ForesterUtil.isEmpty( rank ) && !PhyloXmlUtil.TAXONOMY_RANKS_SET.contains( rank ) ) {
+ if ( !ForesterUtil.isEmpty( rank ) && !TaxonomyUtil.TAXONOMY_RANKS_SET.contains( rank ) ) {
throw new PhyloXmlDataFormatException( "illegal rank: [" + rank + "]" );
}
_rank = rank;
_synonyms = synonyms;
}
- public void setTaxonomyCode( final String taxonomy_code ) throws PhyloXmlDataFormatException {
+ public void setTaxonomyCode( String taxonomy_code ) throws PhyloXmlDataFormatException {
if ( !ForesterUtil.isEmpty( taxonomy_code )
&& !PhyloXmlUtil.TAXOMONY_CODE_PATTERN.matcher( taxonomy_code ).matches() ) {
throw new PhyloXmlDataFormatException( "illegal taxonomy code: [" + taxonomy_code + "]" );
PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.TAXONOMY_AUTHORITY, getAuthority(), indentation );
}
if ( !ForesterUtil.isEmpty( getCommonName() ) ) {
- PhylogenyDataUtil
- .appendElement( writer, PhyloXmlMapping.TAXONOMY_COMMON_NAME, getCommonName(), indentation );
+ PhylogenyDataUtil.appendElement( writer,
+ PhyloXmlMapping.TAXONOMY_COMMON_NAME,
+ getCommonName(),
+ indentation );
}
if ( _synonyms != null ) {
for( final String syn : getSynonyms() ) {
if ( equals( o ) ) {
return 0;
}
- else if ( !ForesterUtil.isEmpty( getScientificName() ) && !ForesterUtil.isEmpty( o.getScientificName() ) ) {
+ if ( ( getIdentifier() != null ) && ( o.getIdentifier() != null )
+ && !ForesterUtil.isEmpty( getIdentifier().getValue() )
+ && !ForesterUtil.isEmpty( o.getIdentifier().getValue() ) ) {
+ final int x = getIdentifier().getValuePlusProvider().compareTo( o.getIdentifier().getValuePlusProvider() );
+ if ( x != 0 ) {
+ return x;
+ }
+ }
+ if ( !ForesterUtil.isEmpty( getScientificName() ) && !ForesterUtil.isEmpty( o.getScientificName() ) ) {
return getScientificName().compareToIgnoreCase( o.getScientificName() );
}
- else if ( !ForesterUtil.isEmpty( getCommonName() ) && !ForesterUtil.isEmpty( o.getCommonName() ) ) {
+ if ( !ForesterUtil.isEmpty( getCommonName() ) && !ForesterUtil.isEmpty( o.getCommonName() ) ) {
return getCommonName().compareToIgnoreCase( o.getCommonName() );
}
- else if ( !ForesterUtil.isEmpty( getTaxonomyCode() ) && !ForesterUtil.isEmpty( o.getTaxonomyCode() ) ) {
+ if ( !ForesterUtil.isEmpty( getTaxonomyCode() ) && !ForesterUtil.isEmpty( o.getTaxonomyCode() ) ) {
return getTaxonomyCode().compareToIgnoreCase( o.getTaxonomyCode() );
}
- return 0;
+ if ( ( getIdentifier() != null ) && ( o.getIdentifier() != null )
+ && !ForesterUtil.isEmpty( getIdentifier().getValue() )
+ && !ForesterUtil.isEmpty( o.getIdentifier().getValue() ) ) {
+ return getIdentifier().getValuePlusProvider().compareTo( o.getIdentifier().getValuePlusProvider() );
+ }
+ return 1;
}
public void setLineage( final List<String> lineage ) {