/**
 * An application that demonstrates the use of lambda expressions.
 * 
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class VectorMathDriver
{
  /**
   * The entry point of the application.
   * 
   * @param args The command line arguments (which are ignored)
   */
  public static void main(String[] args)
  {
    double[] a = {5.0, 3.2, 8.9};
    double[] b = {13.8, 9.4, 7.2};
    double[] c = {6.1, 15.2, 11.1};

    {
//[rectilinear
      double[] nearby = VectorMath.closest(
          // A lambda expression for the rectilinear metric
          (double[] p, double[] q) ->
          {
            double sum = 0.0;
            for (int i=0; i<p.length; i++)
            {
              sum += Math.abs(p[i] - q[i]);
            }
            return sum;
          }, 
          a, b, c);
//]rectilinear
    }


    {
//[Euclidean
      double[] nearby = VectorMath.closest(
          // A lambda expression for the Euclidean metric
          (double[] p, double[] q) ->
          {
            double sum = 0.0;
            for (int i=0; i<p.length; i++)
            {
              sum += Math.pow(p[i] - q[i], 2.0);
            }
            return Math.sqrt(sum);
          }, 
          a, b, c);
//]Euclidean
    }
  }
}
