| 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.inferencexml.model; |
| 27 |
|
| 28 |
import dr.inference.model.DifferenceStatistic; |
| 29 |
import dr.inference.model.Statistic; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class DifferenceStatisticParser extends AbstractXMLObjectParser { |
| 35 |
|
| 36 |
public static String DIFFERENCE_STATISTIC = "differenceStatistic"; |
| 37 |
public static String DIFFERENCE = "difference"; |
| 38 |
public static String ABSOLUTE = "absolute"; |
| 39 |
|
| 40 |
public String[] getParserNames() { |
| 41 |
return new String[]{getParserName(), DIFFERENCE}; |
| 42 |
} |
| 43 |
|
| 44 |
public String getParserName() { |
| 45 |
return DIFFERENCE_STATISTIC; |
| 46 |
} |
| 47 |
|
| 48 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 49 |
|
| 50 |
boolean absolute = xo.getAttribute(ABSOLUTE, false); |
| 51 |
|
| 52 |
Statistic term1 = (Statistic) xo.getChild(0); |
| 53 |
Statistic term2 = (Statistic) xo.getChild(1); |
| 54 |
|
| 55 |
DifferenceStatistic differenceStatistic; |
| 56 |
try { |
| 57 |
differenceStatistic = new DifferenceStatistic(DIFFERENCE_STATISTIC, term1, term2, absolute); |
| 58 |
} catch (IllegalArgumentException iae) { |
| 59 |
throw new XMLParseException("Error parsing " + getParserName() + " the left and right statistics " + |
| 60 |
"should be of the same dimension or of dimension 1"); |
| 61 |
} |
| 62 |
return differenceStatistic; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public String getParserDescription() { |
| 70 |
return "This element returns a statistic that is the difference of the 2 child statistics."; |
| 71 |
} |
| 72 |
|
| 73 |
public Class getReturnType() { |
| 74 |
return DifferenceStatistic.class; |
| 75 |
} |
| 76 |
|
| 77 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 78 |
return rules; |
| 79 |
} |
| 80 |
|
| 81 |
private final XMLSyntaxRule[] rules = { |
| 82 |
AttributeRule.newBooleanRule(ABSOLUTE, true), |
| 83 |
new ElementRule(Statistic.class, "The two operand statistics", 2, 2) |
| 84 |
}; |
| 85 |
|
| 86 |
} |