Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Determines the minimum and maximum values in the <tt>array</tt>. Calls {@link #minMax(double[], double)} with <tt>Double.NaN</tt> as
     * the <tt>noDataValue</tt>.
     * 
     * @param array
     * @return a <tt>double[]</tt> where [0]==minimum and [1]==maximum
     * @see #minMax(double[], double)
     */
    public static double[] minMax(double[] array) {
        return minMax(array, Double.NaN);
    }

    /**
     * Determines the minimum and maximum values in the <tt>array</tt>, ignoring any instances of <tt>noDataValue</tt>.
     * 
     * @param array
     * @param noDataValue
     * @return a <tt>double[]</tt> where [0]==minimum and [1]==maximum
     */
    public static double[] minMax(double[] array, double noDataValue) {
        double[] ret = null;
        double min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY;
        double val;
        for (int i = 0; i < array.length; i++) {
            val = array[i];
            if (val != noDataValue) {
                min = (val < min) ? val : min;
                max = (val > max) ? val : max;
            }
        }
        if (!Double.isInfinite(min) & !Double.isInfinite(max)) {
            ret = new double[] { min, max };
        }

        return ret;
    }

    /**
     * Determines the minimum and maximum values in the two dimensional array <tt>multi</tt>. Calls {@link #minMax(double[], double)} with
     * <tt>Double.NaN</tt> as the <tt>noDataValue</tt>.
     * 
     * @param multi
     * @return a <tt>double[]</tt> where [0]==minimum and [1]==maximum
     * @see #minMax(double[][], double)
     */
    public static double[] minMax(double[][] multi) {
        return minMax(multi, Double.NaN);
    }

    /**
     * Determines the minimum and maximum values in the two dimensional array <tt>multi</tt>, ignoring any instances of <tt>noDataValue</tt>
     * .
     * 
     * @param multi
     * @param noDataValue
     * @return a <tt>double[]</tt> where [0]==minimum and [1]==maximum
     */
    public static double[] minMax(double[][] multi, double noDataValue) {
        double[] ret = null;
        double min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY;
        double val;
        for (int i = 0; i < multi.length; i++) {
            for (int j = 0; j < multi[i].length; j++) {
                val = multi[i][j];
                if (val != noDataValue) {
                    min = (val < min) ? val : min;
                    max = (val > max) ? val : max;
                }
            }
        }
        if (!Double.isInfinite(min) & !Double.isInfinite(max)) {
            ret = new double[] { min, max };
        }

        return ret;
    }

    /**
     * Determines the minimum and maximum values in the <tt>array</tt>. Calls {@link #minMax(float[], float)} with <tt>Float.NaN</tt> as the
     * <tt>noDataValue</tt>.
     * 
     * @param array
     * @return a <tt>float[]</tt> where [0]==minimum and [1]==maximum
     * @see #minMax(float[], float)
     */
    public static float[] minMax(float[] array) {
        return minMax(array, Float.NaN);
    }

    /**
     * Determines the minimum and maximum values in the <tt>array</tt>, ignoring any instances of <tt>noDataValue</tt>.
     * 
     * @param array
     * @param noDataValue
     * @return a <tt>float[]</tt> where [0]==minimum and [1]==maximum
     */
    public static float[] minMax(float[] array, float noDataValue) {
        float[] ret = null;
        float min = Float.POSITIVE_INFINITY, max = Float.NEGATIVE_INFINITY;
        float val;
        for (int i = 0; i < array.length; i++) {
            val = array[i];
            if (val != noDataValue) {
                min = (val < min) ? val : min;
                max = (val > max) ? val : max;
            }
        }
        if (!Float.isInfinite(min) & !Float.isInfinite(max)) {
            ret = new float[] { min, max };
        }

        return ret;
    }

    /**
     * Determines the minimum and maximum values in the two dimensional array <tt>multi</tt>. Calls {@link #minMax(float[], float)} with
     * <tt>Float.NaN</tt> as the <tt>noDataValue</tt>.
     * 
     * @param multi
     * @return a <tt>float[]</tt> where [0]==minimum and [1]==maximum
     * @see #minMax(float[][], float)
     */
    public static float[] minMax(float[][] multi) {
        return minMax(multi, Float.NaN);
    }

    /**
     * Determines the minimum and maximum values in the two dimensional array <tt>multi</tt>, ignoring any instances of <tt>noDataValue</tt>
     * .
     * 
     * @param multi
     * @param noDataValue
     * @return a <tt>float[]</tt> where [0]==minimum and [1]==maximum
     */
    public static float[] minMax(float[][] multi, float noDataValue) {
        float[] ret = null;
        float min = Float.POSITIVE_INFINITY, max = Float.NEGATIVE_INFINITY;
        float val;
        for (int i = 0; i < multi.length; i++) {
            for (int j = 0; j < multi[i].length; j++) {
                val = multi[i][j];
                if (val != noDataValue) {
                    min = (val < min) ? val : min;
                    max = (val > max) ? val : max;
                }
            }
        }
        if (!Float.isInfinite(min) & !Float.isInfinite(max)) {
            ret = new float[] { min, max };
        }

        return ret;
    }
}