moved to: https://sites.google.com/site/cmzmasek/home/software/forester
[jalview.git] / forester / java / src / org / forester / phylogeny / data / BranchWidth.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
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.
13 //
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.
18 //
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
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.phylogeny.data;
27
28 import java.io.IOException;
29 import java.io.Writer;
30
31 import org.forester.io.parsers.nhx.NHXtags;
32 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
33 import org.forester.util.ForesterUtil;
34
35 public class BranchWidth implements PhylogenyData {
36
37     public final static double BRANCH_WIDTH_DEFAULT_VALUE = 1.0;
38     private final double       _value;
39
40     public BranchWidth() {
41         _value = BRANCH_WIDTH_DEFAULT_VALUE;
42     }
43
44     public BranchWidth( final double value ) {
45         _value = value;
46     }
47
48     @Override
49     public StringBuffer asSimpleText() {
50         return new StringBuffer( getValue() + "" );
51     }
52
53     @Override
54     public StringBuffer asText() {
55         return asSimpleText();
56     }
57
58     @Override
59     public PhylogenyData copy() {
60         return new BranchWidth( getValue() );
61     }
62
63     public double getValue() {
64         return _value;
65     }
66
67     @Override
68     public boolean isEqual( final PhylogenyData data ) {
69         return getValue() == ( ( BranchWidth ) data ).getValue();
70     }
71
72     @Override
73     public StringBuffer toNHX() {
74         final StringBuffer sb = new StringBuffer();
75         sb.append( NHXtags.PARENT_BRANCH_WIDTH );
76         sb.append( getValue() );
77         return sb;
78     }
79
80     @Override
81     public void toPhyloXML( final Writer w, final int level, final String indentation ) throws IOException {
82         w.write( ForesterUtil.LINE_SEPARATOR );
83         w.write( indentation );
84         PhylogenyDataUtil.appendElement( w, PhyloXmlMapping.WIDTH, getValue() + "" );
85     }
86
87     @Override
88     public String toString() {
89         return asText().toString();
90     }
91 }