Debian Codegraph @

src/dr/inferencexml/distribution/UniformDistributionModelParser.java

raw symbols SCIP
1 /*
2 * UniformDistributionModelParser.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.inferencexml.distribution;
27
28 import dr.inference.distribution.UniformDistributionModel;
29 import dr.inference.model.Parameter;
30 import dr.xml.*;
31
32 /**
33 * Reads a normal distribution model from a DOM Document element.
34 */
35 public class UniformDistributionModelParser extends AbstractXMLObjectParser {
36
37 public static final String UNIFORM_DISTRIBUTION_MODEL = "uniformDistributionModel";
38 public static final String LOWER = "lower";
39 public static final String UPPER = "upper";
40
41 public String getParserName() {
42 return UNIFORM_DISTRIBUTION_MODEL;
43 }
44
45 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
46
47 Parameter upperParam;
48 Parameter lowerParam;
49
50 XMLObject cxo = xo.getChild(LOWER);
51 if (cxo.getChild(0) instanceof Parameter) {
52 lowerParam = (Parameter) cxo.getChild(Parameter.class);
53 } else {
54 lowerParam = new Parameter.Default(cxo.getDoubleChild(0));
55 }
56
57 cxo = xo.getChild(UPPER);
58 if (cxo.getChild(0) instanceof Parameter) {
59 upperParam = (Parameter) cxo.getChild(Parameter.class);
60 } else {
61 upperParam = new Parameter.Default(cxo.getDoubleChild(0));
62 }
63
64 return new UniformDistributionModel(lowerParam, upperParam);
65 }
66
67 //************************************************************************
68 // AbstractXMLObjectParser implementation
69 //************************************************************************
70
71 public XMLSyntaxRule[] getSyntaxRules() {
72 return rules;
73 }
74
75 private final XMLSyntaxRule[] rules = {
76 new ElementRule(LOWER,
77 new XMLSyntaxRule[]{
78 new XORRule(
79 new ElementRule(Parameter.class),
80 new ElementRule(Double.class)
81 )}
82 ),
83 new ElementRule(UPPER,
84 new XMLSyntaxRule[]{
85 new XORRule(
86 new ElementRule(Parameter.class),
87 new ElementRule(Double.class)
88 )}
89 )
90 };
91
92 public String getParserDescription() {
93 return "Describes a uniform distribution with a given lower and upper bounds ";
94 }
95
96 public Class getReturnType() {
97 return UniformDistributionModel.class;
98 }
99 }