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
7 // Copyright (C) 2000-2001 Washington University School of Medicine
8 // and Howard Hughes Medical Institute
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 // Contact: phylosoft @ gmail . com
26 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
28 package org.forester.phylogeny.data;
30 import java.io.IOException;
31 import java.io.Writer;
32 import java.util.ArrayList;
33 import java.util.List;
35 public class BranchData implements PhylogenyData {
37 private BranchColor _branch_color;
38 private List<Confidence> _confidences;
39 private BranchWidth _branch_width;
45 public void addConfidence( final Confidence confidence ) {
46 getConfidences().add( confidence );
50 public StringBuffer asSimpleText() {
51 throw new UnsupportedOperationException();
55 public StringBuffer asText() {
56 throw new UnsupportedOperationException();
60 public PhylogenyData copy() {
61 final BranchData new_bd = new BranchData();
62 if ( isHasBranchColor() ) {
63 new_bd.setBranchColor( ( BranchColor ) getBranchColor().copy() );
65 if ( isHasBranchWidth() ) {
66 new_bd.setBranchWidth( ( BranchWidth ) getBranchWidth().copy() );
68 if ( isHasConfidences() ) {
69 for( final Confidence confidence : getConfidences() ) {
70 new_bd.addConfidence( ( Confidence ) confidence.copy() );
76 public BranchColor getBranchColor() {
80 public BranchWidth getBranchWidth() {
84 public Confidence getConfidence( final int index ) {
85 return getConfidences().get( index );
88 public List<Confidence> getConfidences() {
89 if ( _confidences == null ) {
90 _confidences = new ArrayList<Confidence>();
95 public int getNumberOfConfidences() {
96 return getConfidences().size();
100 public boolean isEqual( final PhylogenyData data ) {
101 throw new UnsupportedOperationException();
104 public boolean isHasBranchColor() {
105 return getBranchColor() != null;
108 public boolean isHasBranchWidth() {
109 return getBranchWidth() != null;
112 public boolean isHasConfidences() {
113 return getNumberOfConfidences() > 0;
116 public void setBranchColor( final BranchColor branch_color ) {
117 _branch_color = branch_color;
120 public void setBranchWidth( final BranchWidth branch_width ) {
121 _branch_width = branch_width;
125 public StringBuffer toNHX() {
126 final StringBuffer sb = new StringBuffer();
127 if ( isHasConfidences() && ( getConfidence( 0 ).getValue() != Confidence.CONFIDENCE_DEFAULT_VALUE ) ) {
129 sb.append( getConfidence( 0 ).toNHX() );
135 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
136 if ( isHasConfidences() ) {
137 for( final Confidence confidence : getConfidences() ) {
138 confidence.toPhyloXML( writer, level, indentation );
141 if ( isHasBranchWidth() ) {
142 getBranchWidth().toPhyloXML( writer, level, indentation );
144 if ( isHasBranchColor() ) {
145 getBranchColor().toPhyloXML( writer, level, indentation );