Debian Codegraph @

src/dr/evoxml/KStateDataTypeParser.java

raw symbols SCIP
1 /*
2 * KStateDataTypeParser.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.evoxml;
27
28 import dr.evolution.datatype.DataType;
29 import dr.evolution.datatype.GeneralDataType;
30 import dr.xml.*;
31
32 import java.util.ArrayList;
33 import java.util.Collection;
34
35 /**
36 * Package: KStateDataTypeParser
37 * Description:
38 * <p/>
39 * <p/>
40 * Created by
41 *
42 * @author Alexander V. Alekseyenko ([email protected])
43 * Date: Oct 13, 2009
44 * Time: 3:42:14 PM
45 */
46 public class KStateDataTypeParser extends AbstractXMLObjectParser {
47 public static final String K_STATE_DATATYPE = "kStateType";
48 public static final String STATE_COUNT = "stateCount";
49 public static final String START_WITH = "startWith";
50
51 //public static XMLObjectParser PARSER=new KStateDataTypeParser();
52
53 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
54 int k = xo.getIntegerAttribute(STATE_COUNT);
55 int sw = 0;
56 if (xo.hasAttribute(START_WITH))
57 sw = xo.getIntegerAttribute(START_WITH);
58 Collection<String> states = new ArrayList<String>();
59
60 System.err.println(states.toArray().toString());
61
62 for (int i = sw; i < k + sw; ++i) {
63 states.add(Integer.toString(i));
64 }
65 System.err.println("Constructing " + k + "-state datatype");
66 return new GeneralDataType(states);
67 }
68
69 private final XMLSyntaxRule[] rules = {
70 AttributeRule.newIntegerRule(STATE_COUNT, false),
71 AttributeRule.newIntegerRule(START_WITH, true)};
72
73 public XMLSyntaxRule[] getSyntaxRules() {
74 return rules;
75 }
76
77 public String getParserDescription() {
78 return "Parser for k-state model.";
79 }
80
81 public Class getReturnType() {
82 return DataType.class;
83 }
84
85 public String getParserName() {
86 return K_STATE_DATATYPE;
87 }
88
89 }