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: www.phylosoft.org/forester
28 package org.forester.phylogeny.data;
30 import java.io.IOException;
31 import java.io.Writer;
32 import java.math.BigDecimal;
34 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
35 import org.forester.util.ForesterUtil;
37 public class Date implements PhylogenyData {
40 private BigDecimal _value;
41 private BigDecimal _min;
42 private BigDecimal _max;
53 public Date( final String desc ) {
55 throw new IllegalArgumentException( "illegaly empty of null fields in constructor" );
64 public Date( final String desc,
65 final BigDecimal value,
69 if ( ( desc == null ) || ( unit == null ) ) {
70 throw new IllegalArgumentException( "illegaly empty of null fields in constructor" );
80 public StringBuffer asSimpleText() {
81 if ( getValue() != null ) {
82 return new StringBuffer( getDesc() + " [" + getValue().toPlainString() + " " + getUnit() + "]" );
85 return new StringBuffer( getDesc() );
90 public StringBuffer asText() {
91 return asSimpleText();
95 public PhylogenyData copy() {
96 return new Date( getDesc(),
97 getValue() == null ? null : new BigDecimal( getValue().toPlainString() ),
98 getMin() == null ? null : new BigDecimal( getMin().toPlainString() ),
99 getMax() == null ? null : new BigDecimal( getMax().toPlainString() ),
103 public String getDesc() {
107 public BigDecimal getMax() {
111 public BigDecimal getMin() {
115 public String getUnit() {
119 public BigDecimal getValue() {
124 public boolean isEqual( final PhylogenyData data ) {
125 throw new UnsupportedOperationException();
128 public void setDesc( final String desc ) {
132 public void setMax( final BigDecimal max ) {
136 public void setMin( final BigDecimal min ) {
140 public void setUnit( final String unit ) {
144 public void setValue( final BigDecimal value ) {
149 public StringBuffer toNHX() {
150 throw new UnsupportedOperationException();
154 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
155 writer.write( ForesterUtil.LINE_SEPARATOR );
156 writer.write( indentation );
157 PhylogenyDataUtil.appendOpen( writer, PhyloXmlMapping.CLADE_DATE, PhyloXmlMapping.CLADE_DATE_UNIT, getUnit() );
158 if ( !ForesterUtil.isEmpty( getDesc() ) ) {
159 PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.CLADE_DATE_DESC, getDesc(), indentation );
161 if ( getValue() != null ) {
162 PhylogenyDataUtil.appendElement( writer,
163 PhyloXmlMapping.CLADE_DATE_VALUE,
164 getValue().toPlainString(),
167 if ( getMin() != null ) {
168 PhylogenyDataUtil.appendElement( writer,
169 PhyloXmlMapping.CLADE_DATE_MIN,
170 getMin().toPlainString(),
173 if ( getMax() != null ) {
174 PhylogenyDataUtil.appendElement( writer,
175 PhyloXmlMapping.CLADE_DATE_MAX,
176 getMax().toPlainString(),
179 writer.write( ForesterUtil.LINE_SEPARATOR );
180 writer.write( indentation );
181 PhylogenyDataUtil.appendClose( writer, PhyloXmlMapping.CLADE_DATE );
185 public String toString() {
186 return asSimpleText().toString();