package dr.inferencexml.operators;

import dr.inference.model.Parameter;
import dr.inference.operators.MCMCOperator;
import dr.inference.operators.UniformIntegerOperator;
import dr.xml.*;

/**
 */
public class UniformIntegerOperatorParser extends AbstractXMLObjectParser {

    public final static String UNIFORM_INTEGER_OPERATOR = "uniformIntegerOperator";

    public String getParserName() {
        return UNIFORM_INTEGER_OPERATOR;
    }

    public Object parseXMLObject(XMLObject xo) throws XMLParseException {

        double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);

        Parameter parameter = (Parameter) xo.getChild(Parameter.class);

        int lower = (int) (double) parameter.getBounds().getLowerLimit(0);
        if (xo.hasAttribute("lower")) lower = xo.getIntegerAttribute("lower");

        int upper = (int) (double) parameter.getBounds().getUpperLimit(0);
        if (xo.hasAttribute("upper")) upper = xo.getIntegerAttribute("upper");

        if (upper == lower || lower == (int) Double.NEGATIVE_INFINITY || upper == (int) Double.POSITIVE_INFINITY) {
            throw new XMLParseException(this.getParserName() + " boundaries not found in parameter " + parameter.getParameterName() + " Use operator lower and upper !");
        }

        return new UniformIntegerOperator(parameter, lower, upper, weight);
    }

    //************************************************************************
    // AbstractXMLObjectParser implementation
    //************************************************************************

    public String getParserDescription() {
        return "An operator that picks new parameter values uniformly at random.";
    }

    public Class getReturnType() {
        return UniformIntegerOperator.class;
    }


    public XMLSyntaxRule[] getSyntaxRules() {
        return rules;
    }

    private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
            AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
            AttributeRule.newDoubleRule("upper", true),
            AttributeRule.newDoubleRule("lower", true),
            new ElementRule(Parameter.class)
    };
}

@@ -984,32 +984,138 @@
 te(%22upper%22);%0D%0A%0D%0A
+        int count = 1;%0D%0A        if (xo.hasAttribute(%22count%22)) count = xo.getIntegerAttribute(%22count%22);%0D%0A%0D%0A
         if (uppe
@@ -1315,16 +1315,37 @@
 ameter %22
+%0D%0A                   
  + param
@@ -1493,16 +1493,23 @@
 , weight
+, count
 );%0D%0A    
@@ -2043,16 +2043,22 @@
 private 
+final 
 XMLSynta
@@ -2077,27 +2077,8 @@
 s = 
-new XMLSyntaxRule%5B%5D
 %7B%0D%0A 
@@ -2245,32 +2245,89 @@
 lower%22, true),%0D%0A
+            AttributeRule.newDoubleRule(%22count%22, true),%0D%0A
             new 

Allow multiple moves in operator (via a user speciefied 'count')