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
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: https://sites.google.com/site/cmzmasek/home/software/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.Collections;
32 import java.util.Comparator;
33 import java.util.List;
35 import org.forester.util.ForesterUtil;
37 public class PropertiesList implements PhylogenyData {
39 private final List<Property> _properties;
40 private final Comparator<Property> comp = new Comparator<Property>() {
43 public int compare( final Property p1, final Property p2 ) {
44 return p2.getRef().compareTo( p1.getRef() );
48 public PropertiesList() {
49 _properties = new ArrayList<Property>();
53 return _properties.size();
56 public void addProperty( final Property property ) throws IllegalArgumentException {
57 _properties.add( property );
58 Collections.sort( _properties, comp );
62 public StringBuffer asSimpleText() {
63 final StringBuffer sb = new StringBuffer();
65 for( final Property p : getProperties() ) {
72 sb.append( p.asText() );
78 public StringBuffer asText() {
79 return asSimpleText();
83 public PhylogenyData copy() {
84 final PropertiesList new_one = new PropertiesList();
85 for( final Property r : getProperties() ) {
86 new_one.addProperty( r );
91 public List<Property> getProperties() {
95 public List<Property> getPropertiesWithGivenReferencePrefix( final String ref_prefix )
96 throws IllegalArgumentException {
97 if ( ForesterUtil.isEmpty( ref_prefix ) ) {
98 throw new IllegalArgumentException( "reference prefix is null or empty" );
100 final String my_ref_prefix = new String( ref_prefix.trim() );
101 final List<Property> props = new ArrayList<Property>();
102 for( final Property p : getProperties() ) {
103 if ( p.getRef().startsWith( my_ref_prefix ) ) {
110 public List<Property> getProperties( final String ref ) throws IllegalArgumentException {
111 final List<Property> props = new ArrayList<Property>();
112 for( final Property p : getProperties() ) {
113 if ( p.getRef().equals( ref ) ) {
121 public boolean isEqual( final PhylogenyData data ) {
122 throw new UnsupportedOperationException();
126 public StringBuffer toNHX() {
127 throw new UnsupportedOperationException();
131 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
132 if ( getProperties() != null ) {
133 for( final Property p : getProperties() ) {
134 p.toPhyloXML( writer, level, indentation );
140 public String toString() {
141 return asSimpleText().toString();