| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 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 |
|
| 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 |
} |