2 package org.forester.phylogeny.data;
4 import java.io.IOException;
6 import java.math.BigDecimal;
8 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
9 import org.forester.util.ForesterUtil;
11 public class Point implements PhylogenyData {
13 private final String _geodetic_datum;
14 private final BigDecimal _lat;
15 private final BigDecimal _long;
16 private final BigDecimal _alt;
17 private final String _alt_unit;
18 public static final String UNKNOWN_GEODETIC_DATUM = "?";
21 this( UNKNOWN_GEODETIC_DATUM, null, null, null, "" );
24 public Point( final String geodetic_datum, final BigDecimal lat, final BigDecimal longitude ) {
25 this( geodetic_datum, lat, longitude, null, "" );
28 public boolean isEmpty() {
29 return ( _lat == null ) && ( _long == null ) && ( _alt == null );
32 public Point( final String geodetic_datum,
34 final BigDecimal longitude,
36 final String alt_unit ) {
37 if ( ForesterUtil.isEmpty( geodetic_datum ) ) {
38 throw new IllegalArgumentException( "illegal attempt to use empty geodetic datum" );
40 if ( ( alt != null ) && ForesterUtil.isEmpty( alt_unit ) ) {
41 throw new IllegalArgumentException( "altitude must hava a unit" );
43 _geodetic_datum = geodetic_datum;
51 public StringBuffer asSimpleText() {
53 return new StringBuffer();
55 else if ( getAltitude() == null ) {
56 return new StringBuffer( "[" + getLatitude().toPlainString() + ", " + getLongitude() + "]" );
59 return new StringBuffer( "[" + getLatitude().toPlainString() + ", " + getLongitude() + ", " + getAltitude()
60 + getAltiudeUnit() + "]" );
65 public StringBuffer asText() {
66 return asSimpleText();
70 public PhylogenyData copy() {
71 return new Point( getGeodeticDatum(),
72 getLatitude() == null ? null : new BigDecimal( getLatitude().toPlainString() ),
73 getLongitude() == null ? null : new BigDecimal( getLongitude().toPlainString() ),
74 getAltitude() == null ? null : new BigDecimal( getAltitude().toPlainString() ),
78 public BigDecimal getAltitude() {
82 public String getAltiudeUnit() {
86 public String getGeodeticDatum() {
87 return _geodetic_datum;
90 public BigDecimal getLatitude() {
94 public BigDecimal getLongitude() {
99 public boolean isEqual( final PhylogenyData point ) {
100 throw new UnsupportedOperationException();
104 public StringBuffer toNHX() {
105 throw new UnsupportedOperationException();
109 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
113 writer.write( ForesterUtil.LINE_SEPARATOR );
114 writer.write( indentation );
115 if ( getAltitude() != null ) {
116 PhylogenyDataUtil.appendOpen( writer,
117 PhyloXmlMapping.POINT,
118 PhyloXmlMapping.POINT_GEODETIC_DATUM,
120 PhyloXmlMapping.POINT_ALTITUDE_UNIT_ATTR,
124 PhylogenyDataUtil.appendOpen( writer,
125 PhyloXmlMapping.POINT,
126 PhyloXmlMapping.POINT_GEODETIC_DATUM,
127 getGeodeticDatum() );
129 PhylogenyDataUtil.appendElement( writer,
130 PhyloXmlMapping.POINT_LATITUDE,
131 getLatitude().toPlainString(),
133 PhylogenyDataUtil.appendElement( writer,
134 PhyloXmlMapping.POINT_LONGITUDE,
135 getLongitude().toPlainString(),
137 if ( getAltitude() != null ) {
138 PhylogenyDataUtil.appendElement( writer,
139 PhyloXmlMapping.POINT_ALTITUDE,
140 getAltitude().toPlainString(),
143 writer.write( ForesterUtil.LINE_SEPARATOR );
144 writer.write( indentation );
145 PhylogenyDataUtil.appendClose( writer, PhyloXmlMapping.POINT );
149 public String toString() {
150 return asSimpleText().toString();