001/*
002
003 *                    BioJava development code
004
005 *
006
007 * This code may be freely distributed and modified under the
008
009 * terms of the GNU Lesser General Public Licence.  This should
010
011 * be distributed with the code.  If you do not have a copy,
012
013 * see:
014
015 *
016
017 *      http://www.gnu.org/copyleft/lesser.html
018
019 *
020
021 * Copyright for this code is held jointly by the individual
022
023 * authors.  These should be listed in @author doc comments.
024
025 *
026
027 * For more information on the BioJava project and its aims,
028
029 * or to join the biojava-l mailing list, visit the home page
030
031 * at:
032
033 *
034
035 *      http://www.biojava.org/
036
037 *
038
039 */
040
041package org.biojava.bio.seq.io.agave;
042
043import java.util.ArrayList;
044import java.util.Iterator;
045import java.util.List;
046
047
048
049/**
050
051 * 
052
053 * @author Hanning Ni    Doubletwist Inc
054  * @author Greg Cox
055
056 */
057
058public class AGAVERelatedAnnot {
059
060  private List element_ids ;
061
062  private List props ;
063
064  private String rel ;
065
066  private String score ;
067
068
069
070  /** construct.. **/
071
072  public AGAVERelatedAnnot() {
073
074      element_ids = new ArrayList(1) ;
075
076  }
077
078
079
080
081
082  public void setRel(String rel)
083
084  {
085
086      this.rel = rel  ;
087
088  }
089
090  public void setScore(String score)
091
092  {
093
094      this.score = score ;
095
096  }
097
098  /**  @param id is content of the tag of <element_id> **/
099
100  public void addElementId(String id)
101
102  {
103
104      element_ids .add( id );
105
106  }
107
108  public void addProp(AGAVEProperty prop)
109
110  {
111
112      if( props == null ) //lazy realization
113
114          props = new ArrayList(1) ;
115
116      props.add(prop);
117
118  }
119
120  public String getScore()
121
122  {
123
124      return score ;
125
126  }
127
128  public String getRel()
129
130  {
131
132      return rel ;
133
134  }
135
136  public String[] getElementIds()
137
138  {
139
140      String[]  tmp = new String[ element_ids.size() ] ;
141
142      return (String[]) element_ids.toArray( tmp ) ;
143
144  }
145
146  public AGAVEProperty[] getProps()
147
148  {
149
150      AGAVEProperty[] tmp = new AGAVEProperty[ props.size() ] ;
151
152      return (AGAVEProperty[]) props.toArray( tmp ) ;
153
154  }
155
156  public String toString(String indent, String indent_unit)
157
158  {
159
160      StringBuffer tmp = new StringBuffer() ;
161
162      tmp.append(indent +  "<related_annot rel=\"" + rel + "\"" ) ;
163
164      if( score != null )
165
166         tmp.append(" score=\"" + score + "\"") ;
167
168      tmp.append(">" + "\n") ;
169
170      Iterator it = element_ids.iterator() ;
171
172      while( it.hasNext() )
173
174      {
175
176          tmp.append( indent + indent_unit + "<element_id id=\"" + (String)it.next() + "\"/>" + "\n" ) ;
177
178      }
179
180      it = props.iterator() ;
181
182      while( it.hasNext() )
183
184      {
185
186          tmp.append( ((AGAVEProperty) it.next()).toString(indent + indent_unit, indent_unit) ) ;
187
188      }
189
190      tmp.append(indent + "</related_annot>" + "\n") ;
191
192      return tmp.substring(0) ;
193
194  }
195
196   public String toString()
197
198  {
199
200      StringBuffer tmp = new StringBuffer() ;
201
202      tmp.append( "<related_annot rel=\"" + rel + "\"" ) ;
203
204      if( score != null )
205
206         tmp.append(" score=\"" + score + "\"") ;
207
208      tmp.append(">" + "\n") ;
209
210      Iterator it = element_ids.iterator() ;
211
212      while( it.hasNext() )
213
214      {
215
216          tmp.append("<element_id id=\"" + (String)it.next() + "\"/>" + "\n" ) ;
217
218      }
219
220      it = props.iterator() ;
221
222      while( it.hasNext() )
223
224      {
225
226          tmp.append( (AGAVEProperty) it.next() ) ;
227
228      }
229
230      tmp.append("</related_annot>" + "\n") ;
231
232      return tmp.substring(0) ;
233
234  }
235
236}