1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
// $Id:
// FORESTER -- software libraries and applications
// for evolutionary biology research and applications.
//
// Copyright (C) 2008-2009 Christian M. Zmasek
// Copyright (C) 2008-2009 Burnham Institute for Medical Research
// Copyright (C) 2000-2001 Washington University School of Medicine
// and Howard Hughes Medical Institute
// All rights reserved
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
//
// Contact: phylosoft @ gmail . com
// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
package org.forester.phylogeny.data;
import java.io.IOException;
import java.io.Writer;
import java.math.BigDecimal;
import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
import org.forester.util.ForesterUtil;
public class Date implements PhylogenyData {
private String _desc;
private BigDecimal _value;
private BigDecimal _min;
private BigDecimal _max;
private String _unit;
public Date() {
_desc = "";
_value = null;
_min = null;
_max = null;
_unit = "";
}
public Date( final String desc ) {
if ( desc == null ) {
throw new IllegalArgumentException( "illegaly empty of null fields in constructor" );
}
_desc = desc;
_value = null;
_min = null;
_max = null;
_unit = "";
}
public Date( final String desc,
final BigDecimal value,
final BigDecimal min,
final BigDecimal max,
final String unit ) {
if ( ( desc == null ) || ( unit == null ) ) {
throw new IllegalArgumentException( "illegaly empty of null fields in constructor" );
}
_desc = desc;
_value = value;
_min = min;
_max = max;
_unit = unit;
}
@Override
public StringBuffer asSimpleText() {
if ( getValue() != null ) {
return new StringBuffer( getDesc() + " [" + getValue().toPlainString() + " " + getUnit() + "]" );
}
else {
return new StringBuffer( getDesc() );
}
}
@Override
public StringBuffer asText() {
return asSimpleText();
}
@Override
public PhylogenyData copy() {
return new Date( getDesc(),
getValue() == null ? null : new BigDecimal( getValue().toPlainString() ),
getMin() == null ? null : new BigDecimal( getMin().toPlainString() ),
getMax() == null ? null : new BigDecimal( getMax().toPlainString() ),
getUnit() );
}
public String getDesc() {
return _desc;
}
public BigDecimal getMax() {
return _max;
}
public BigDecimal getMin() {
return _min;
}
public String getUnit() {
return _unit;
}
public BigDecimal getValue() {
return _value;
}
@Override
public boolean isEqual( final PhylogenyData data ) {
throw new UnsupportedOperationException();
}
public void setDesc( final String desc ) {
_desc = desc;
}
public void setMax( final BigDecimal max ) {
_max = max;
}
public void setMin( final BigDecimal min ) {
_min = min;
}
public void setUnit( final String unit ) {
_unit = unit;
}
public void setValue( final BigDecimal value ) {
_value = value;
}
@Override
public StringBuffer toNHX() {
throw new UnsupportedOperationException();
}
@Override
public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
writer.write( ForesterUtil.LINE_SEPARATOR );
writer.write( indentation );
PhylogenyDataUtil.appendOpen( writer, PhyloXmlMapping.CLADE_DATE, PhyloXmlMapping.CLADE_DATE_UNIT, getUnit() );
if ( !ForesterUtil.isEmpty( getDesc() ) ) {
PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.CLADE_DATE_DESC, getDesc(), indentation );
}
if ( getValue() != null ) {
PhylogenyDataUtil.appendElement( writer,
PhyloXmlMapping.CLADE_DATE_VALUE,
getValue().toPlainString(),
indentation );
}
if ( getMin() != null ) {
PhylogenyDataUtil.appendElement( writer,
PhyloXmlMapping.CLADE_DATE_MIN,
getMin().toPlainString(),
indentation );
}
if ( getMax() != null ) {
PhylogenyDataUtil.appendElement( writer,
PhyloXmlMapping.CLADE_DATE_MAX,
getMax().toPlainString(),
indentation );
}
writer.write( ForesterUtil.LINE_SEPARATOR );
writer.write( indentation );
PhylogenyDataUtil.appendClose( writer, PhyloXmlMapping.CLADE_DATE );
}
@Override
public String toString() {
return asSimpleText().toString();
}
}
|