2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.phylogeny.data;
28 import java.io.IOException;
29 import java.io.Writer;
31 import org.forester.io.parsers.nhx.NHXtags;
32 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
33 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
34 import org.forester.util.ForesterUtil;
36 public class Confidence implements PhylogenyData, Comparable<Confidence> {
38 public final static double CONFIDENCE_DEFAULT_VALUE = -9999.0;
39 private double _value;
46 public Confidence( final double value, final String type ) {
52 public StringBuffer asSimpleText() {
53 return new StringBuffer().append( ForesterUtil.FORMATTER_6.format( getValue() ) );
57 public StringBuffer asText() {
58 final StringBuffer sb = new StringBuffer();
59 if ( !ForesterUtil.isEmpty( getType() ) ) {
61 sb.append( getType() );
64 sb.append( ForesterUtil.FORMATTER_6.format( getValue() ) );
69 public int compareTo( final Confidence confidence ) {
70 if ( this == confidence ) {
73 return getType().compareToIgnoreCase( confidence.getType() );
77 public PhylogenyData copy() {
78 return new Confidence( getValue(), getType() );
81 public String getType() {
85 public double getValue() {
90 setValue( CONFIDENCE_DEFAULT_VALUE );
95 public boolean isEqual( final PhylogenyData confidence ) {
96 if ( confidence == null ) {
99 if ( !( confidence instanceof Confidence ) ) {
102 final Confidence s = ( Confidence ) confidence;
103 if ( s.getValue() != getValue() ) {
106 if ( !s.getType().equals( getType() ) ) {
112 public void setType( final String type ) {
116 public void setValue( final double value ) {
121 public StringBuffer toNHX() {
122 final StringBuffer sb = new StringBuffer();
123 sb.append( NHXtags.SUPPORT );
124 sb.append( getValue() );
129 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
130 if ( getValue() == CONFIDENCE_DEFAULT_VALUE ) {
133 writer.write( ForesterUtil.LINE_SEPARATOR );
134 writer.write( indentation );
135 PhylogenyDataUtil.appendElement( writer,
136 PhyloXmlMapping.CONFIDENCE,
137 String.valueOf( ForesterUtil
139 PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) ),
140 PhyloXmlMapping.CONFIDENCE_TYPE_ATTR,
141 ForesterUtil.isEmpty( getType() ) ? "unknown" : getType() );
145 public String toString() {
146 return asText().toString();