Debian Codegraph @

src/dr/evoxml/util/XMLUnits.java

raw symbols SCIP
1 /*
2 * XMLUnits.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.util;
27
28 import dr.evolution.util.Units;
29 import dr.xml.StringAttributeRule;
30 import dr.xml.XMLObject;
31 import dr.xml.XMLParseException;
32 import dr.xml.XMLSyntaxRule;
33
34 /**
35 * @author Alexei Drummond
36 * @version $Id: XMLUnits.java,v 1.2 2005/05/24 20:25:59 rambaut Exp $
37 */
38 public interface XMLUnits extends Units {
39
40 final static String GENERATIONS = "generations";
41 final static String DAYS = "days";
42 final static String MONTHS = "months";
43 final static String YEARS = "years";
44 public final static String SUBSTITUTIONS = "substitutions";
45 // Mutations has been replaced with substitutions...
46 final static String MUTATIONS = "mutations";
47 final static String UNKNOWN = "unknown";
48
49 public final static String UNITS = "units";
50
51 XMLSyntaxRule UNITS_RULE = new StringAttributeRule("units", "the units", UNIT_NAMES, false);
52 XMLSyntaxRule[] SYNTAX_RULES = {UNITS_RULE};
53
54 class Utils {
55
56 public static Units.Type getUnitsAttr(XMLObject
57 xo) throws XMLParseException {
58
59 Units.Type units = dr.evolution.util.Units.Type.GENERATIONS;
60 if (xo.hasAttribute(UNITS)) {
61 String unitsAttr = (String) xo.getAttribute(UNITS);
62 if (unitsAttr.equals(YEARS)) {
63 units = dr.evolution.util.Units.Type.YEARS;
64 } else if (unitsAttr.equals(MONTHS)) {
65 units = dr.evolution.util.Units.Type.MONTHS;
66 } else if (unitsAttr.equals(DAYS)) {
67 units = dr.evolution.util.Units.Type.DAYS;
68 } else if (unitsAttr.equals(SUBSTITUTIONS) || unitsAttr.equals(MUTATIONS)) {
69 units = dr.evolution.util.Units.Type.SUBSTITUTIONS;
70 }
71 }
72 return units;
73 }
74
75 }
76 }