| 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.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 |
|
| 36 |
|
| 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 |
|
| 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 |
} |