package com.srbenoit.math.solvers;

import com.srbenoit.math.linear.TupleN;

/**
 * A system of functions to be evaluated.
 */
public class SystemOfFunctions {

    /** the functions. */
    private transient AbstractFunction[] functions;

    /**
     * Constructs a new <code>SystemOfFunctions</code>.
     *
     * @param  numFunctions  the number of functions in the system
     */
    public SystemOfFunctions(final int numFunctions) {

        this.functions = new AbstractFunction[numFunctions];
    }

    /**
     * Get the number of functions in the list.
     *
     * @return  the number of functions
     */
    public final int numFunctions() {

        return this.functions.length;
    }

    /**
     * Install a function in the system.
     *
     * @param  index     the index of the function
     * @param  function  the function
     */
    public final void setFunction(final int index, final AbstractFunction function) {

        this.functions[index] = function;
    }

    /**
     * Get a particular function.
     *
     * @param   index  the index of the function to get
     * @return  the function
     */
    public final AbstractFunction getFunction(final int index) {

        return this.functions[index];
    }

    /**
     * Pre-computes values used by all functions for one particular set of coordinates. This
     * implementation does nothing. Subclasses can override to perform problem-specific
     * pre-computation.
     *
     * @param  coordinates  the coordinates at which to compute values
     */
    public void precompute(@SuppressWarnings("unused") final TupleN coordinates) {

        // Empty
    }
}
