Debian Codegraph @

src/dr/evomodel/alloppnet/parsers/AlloppSpeciesBindingsApSpInfoParser.java

raw symbols SCIP
1 /*
2 * AlloppSpeciesBindingsApSpInfoParser.java
3 *
4 * Copyright (c) 2002-2017 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.evomodel.alloppnet.parsers;
27
28
29 import dr.evomodel.alloppnet.speciation.AlloppSpeciesBindings;
30 import dr.xml.AbstractXMLObjectParser;
31 import dr.xml.AttributeRule;
32 import dr.xml.ElementRule;
33 import dr.xml.XMLObject;
34 import dr.xml.XMLParseException;
35 import dr.xml.XMLSyntaxRule;
36
37
38 /**
39 *
40 * Parses a possibly-allopolyploid species made of individual organisms.
41 *
42 * @author Graham Jones
43 * Date: 18/04/2011
44 */
45
46
47
48 /*
49 *
50 * Parses a diploid or allopolyploid species, recording ploidy level
51 * and running through all individual organisms belonging to the species.
52 *
53 * Part of parsing a AlloppSpeciesBindings.
54 *
55 */
56
57
58 public class AlloppSpeciesBindingsApSpInfoParser extends
59 AbstractXMLObjectParser {
60 public static final String APSP = "apsp";
61 public static final String PLOIDYLEVEL = "ploidylevel";
62
63 public String getParserName() {
64 return APSP;
65 }
66
67 @Override
68 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
69 AlloppSpeciesBindings.Individual[] individuals =
70 new AlloppSpeciesBindings.Individual[xo.getChildCount()];
71 for (int ni = 0; ni < individuals.length; ++ni) {
72 individuals[ni] = (AlloppSpeciesBindings.Individual) xo.getChild(ni);
73 }
74 return new AlloppSpeciesBindings.ApSpInfo(xo.getId(), xo.getIntegerAttribute(PLOIDYLEVEL), individuals);
75 }
76
77 @Override
78 public XMLSyntaxRule[] getSyntaxRules() {
79 return new XMLSyntaxRule[] {
80 AttributeRule.newDoubleRule(PLOIDYLEVEL),
81 new ElementRule(AlloppSpeciesBindings.Individual.class, 1, Integer.MAX_VALUE)
82 };
83 }
84
85 @Override
86 public String getParserDescription() {
87 return "A diploid or allopolyploid species made of individuals";
88 }
89
90 @Override
91 public Class getReturnType() {
92 return AlloppSpeciesBindings.ApSpInfo.class;
93 }
94
95 }