in progress
[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.phyloxml.PhyloXmlMapping;
32 import org.forester.util.ForesterUtil;
33
34 public class BranchWidth implements PhylogenyData {
35
36     public final static double BRANCH_WIDTH_DEFAULT_VALUE = 1.0;
37     private final double       _value;
38
39     public BranchWidth() {
40         _value = BRANCH_WIDTH_DEFAULT_VALUE;
41     }
42
43     public BranchWidth( final double value ) {
44         _value = value;
45     }
46
47     @Override
48     public StringBuffer asSimpleText() {
49         return new StringBuffer( getValue() + "" );
50     }
51
52     @Override
53     public StringBuffer asText() {
54         return asSimpleText();
55     }
56
57     @Override
58     public PhylogenyData copy() {
59         return new BranchWidth( getValue() );
60     }
61
62     public double getValue() {
63         return _value;
64     }
65
66     @Override
67     public boolean isEqual( final PhylogenyData data ) {
68         return getValue() == ( ( BranchWidth ) data ).getValue();
69     }
70
71     @Override
72     public StringBuffer toNHX() {
73         throw new UnsupportedOperationException();
74     }
75
76     @Override
77     public void toPhyloXML( final Writer w, final int level, final String indentation ) throws IOException {
78         w.write( ForesterUtil.LINE_SEPARATOR );
79         w.write( indentation );
80         PhylogenyDataUtil.appendElement( w, PhyloXmlMapping.WIDTH, getValue() + "" );
81     }
82
83     @Override
84     public String toString() {
85         return asText().toString();
86     }
87 }