package server;

/**
 * Executor class for XML-RPC communication
 * 
 * @author Tinsae Ghilay
 *         based on tutorial from
 *         https://www.tutorialspoint.com/xml-rpc/xml_rpc_examples.htm
 */
public class Executor {

    // define methods that can be called remotely

    /**
     * sum of two integers
     * 
     * @param x
     * @param y
     * @return
     */
    public Integer add(Integer x, Integer y) {
        return Integer.valueOf(x + y);
    }

    /**
     * difference of two integers x - y
     * 
     * @param x
     * @param y
     * @return
     */
    public Integer subtract(Integer x, Integer y) {
        return Integer.valueOf(x - y);
    }

    /**
     * product of two integers
     * 
     * @param x
     * @param y
     * @return
     */
    public Integer multiply(Integer x, Integer y) {
        return Integer.valueOf(x * y);
    }

    /**
     * division of two integers x/y
     * 
     * @param x
     * @param y
     * @return
     */
    public Double divide(Integer x, Integer y) {
        return Double.valueOf((double) x / y);
    }

    /**
     * modulus of two integers
     * 
     * @param x
     * @param y
     * @return
     */
    public Integer mod(Integer x, Integer y) {
        return Integer.valueOf(x % y);
    }

    /**
     * power of two integers x^y
     * 
     * @param x
     * @param y
     * @return
     */
    public Integer power(Integer x, Integer y) {
        return Integer.valueOf((int) Math.pow(x, y));
    }

    /**
     * root of two integers X√Y
     * 
     * @param x
     * @param y
     * @return
     */
    public Integer root(Integer x, Integer y) {
        return Integer.valueOf((int) Math.pow(x, 1.0 / y));
    }

}
