// Copyright (C) 2008-2009 Christian M. Zmasek
// Copyright (C) 2008-2009 Burnham Institute for Medical Research
// All rights reserved
// Copyright (C) 2008-2009 Christian M. Zmasek
// Copyright (C) 2008-2009 Burnham Institute for Medical Research
// All rights reserved
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
//
// Contact: phylosoft @ gmail . com
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
//
// Contact: phylosoft @ gmail . com
import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
import org.forester.util.ForesterUtil;
import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
import org.forester.util.ForesterUtil;
public void addUri( final Uri uri ) {
if ( getUris() == null ) {
setUris( new ArrayList<Uri>() );
public void addUri( final Uri uri ) {
if ( getUris() == null ) {
setUris( new ArrayList<Uri>() );
public StringBuffer asText() {
final StringBuffer sb = new StringBuffer();
if ( getIdentifier() != null ) {
public StringBuffer asText() {
final StringBuffer sb = new StringBuffer();
if ( getIdentifier() != null ) {
t.setScientificName( getScientificName() );
t.setCommonName( getCommonName() );
t.setAuthority( getAuthority() );
t.setScientificName( getScientificName() );
t.setCommonName( getCommonName() );
t.setAuthority( getAuthority() );
if ( getUris() != null ) {
t.setUris( new ArrayList<Uri>() );
for( final Uri uri : getUris() ) {
if ( getUris() != null ) {
t.setUris( new ArrayList<Uri>() );
for( final Uri uri : getUris() ) {
}
public boolean isEmpty() {
return ( ( getIdentifier() == null ) && ForesterUtil.isEmpty( getTaxonomyCode() )
&& ForesterUtil.isEmpty( getCommonName() ) && ForesterUtil.isEmpty( getScientificName() )
}
public boolean isEmpty() {
return ( ( getIdentifier() == null ) && ForesterUtil.isEmpty( getTaxonomyCode() )
&& ForesterUtil.isEmpty( getCommonName() ) && ForesterUtil.isEmpty( getScientificName() )
* 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
* 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.)
* 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.)
- if ( ( getIdentifier() != null ) && ( tax.getIdentifier() != null ) ) {
+ if ( ( getIdentifier() != null ) && ( tax.getIdentifier() != null )
+ && !ForesterUtil.isEmpty( getIdentifier().getValue() )
+ && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
return getIdentifier().isEqual( tax.getIdentifier() );
}
else if ( !ForesterUtil.isEmpty( getTaxonomyCode() ) && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
return getIdentifier().isEqual( tax.getIdentifier() );
}
else if ( !ForesterUtil.isEmpty( getTaxonomyCode() ) && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
else if ( !ForesterUtil.isEmpty( getCommonName() ) && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
return getCommonName().equalsIgnoreCase( tax.getCommonName() );
}
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 setRank( final String rank ) {
- if ( !ForesterUtil.isEmpty( rank ) && !PhyloXmlUtil.TAXONOMY_RANKS.contains( rank ) ) {
+ public void setRank( final String rank ) throws PhyloXmlDataFormatException {
+ if ( !ForesterUtil.isEmpty( rank ) && !TaxonomyUtil.TAXONOMY_RANKS_SET.contains( rank ) ) {
if ( !ForesterUtil.isEmpty( taxonomy_code )
&& !PhyloXmlUtil.TAXOMONY_CODE_PATTERN.matcher( taxonomy_code ).matches() ) {
throw new PhyloXmlDataFormatException( "illegal taxonomy code: [" + taxonomy_code + "]" );
if ( !ForesterUtil.isEmpty( taxonomy_code )
&& !PhyloXmlUtil.TAXOMONY_CODE_PATTERN.matcher( taxonomy_code ).matches() ) {
throw new PhyloXmlDataFormatException( "illegal taxonomy code: [" + taxonomy_code + "]" );
public StringBuffer toNHX() {
final StringBuffer sb = new StringBuffer();
if ( getIdentifier() != null ) {
public StringBuffer toNHX() {
final StringBuffer sb = new StringBuffer();
if ( getIdentifier() != null ) {
public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
if ( isEmpty() ) {
return;
public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
if ( isEmpty() ) {
return;
PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.TAXONOMY_AUTHORITY, getAuthority(), indentation );
}
if ( !ForesterUtil.isEmpty( getCommonName() ) ) {
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 );
- 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() ) ) {
+ 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 ) {
+ _lineage = lineage;
+ }
+
+ public List<String> getLineage() {
+ return _lineage;