2 // forester -- software libraries and applications
3 // for genomics and evolutionary biology research.
5 // Copyright (C) 2010 Christian M Zmasek
6 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
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.
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.
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
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.phylogeny.data;
28 import java.io.IOException;
29 import java.io.Writer;
30 import java.util.ArrayList;
31 import java.util.List;
33 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
34 import org.forester.io.writers.PhylogenyWriter;
35 import org.forester.util.ForesterUtil;
37 public class Polygon implements PhylogenyData {
39 private final List<Point> _points;
41 public Polygon( final List<Point> points ) {
46 public StringBuffer asSimpleText() {
47 final StringBuffer sb = new StringBuffer();
49 for( final Point point : getPoints() ) {
54 sb.append( ForesterUtil.LINE_SEPARATOR );
56 sb.append( point.asSimpleText() );
62 public StringBuffer asText() {
63 return asSimpleText();
67 public PhylogenyData copy() {
68 final List<Point> new_points = new ArrayList<Point>();
69 for( final Point point : getPoints() ) {
70 new_points.add( ( Point ) point.copy() );
72 return new Polygon( new_points );
75 public List<Point> getPoints() {
79 public boolean isEmpty() {
80 return ForesterUtil.isEmpty( _points );
84 public boolean isEqual( final PhylogenyData data ) {
85 throw new UnsupportedOperationException();
89 public StringBuffer toNHX() {
90 throw new UnsupportedOperationException();
94 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
98 writer.write( ForesterUtil.LINE_SEPARATOR );
99 writer.write( indentation );
100 PhylogenyDataUtil.appendOpen( writer, PhyloXmlMapping.POLYGON );
101 for( final Point point : getPoints() ) {
102 point.toPhyloXML( writer, level, indentation + PhylogenyWriter.PHYLO_XML_INTENDATION_BASE );
103 writer.write( indentation );
105 writer.write( ForesterUtil.LINE_SEPARATOR );
106 writer.write( indentation );
107 PhylogenyDataUtil.appendClose( writer, PhyloXmlMapping.POLYGON );