Java Array Average average(final T p_num1, final T p_num2)

Here you can find the source of average(final T p_num1, final T p_num2)

Description

average

License

Open Source License

Declaration

public static <T extends Number> Double average(final T p_num1, final T p_num2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 Lab-STICC Universite de Bretagne Sud, Lorient.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the CeCILL-B license available
 * at ://w  w w .j a v  a  2  s  .  c o m
 * en : http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
 * fr : http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
 * 
 * Contributors:
 * Dominique BLOUIN (Lab-STICC UBS), dominique.blouin@univ-ubs.fr
 ******************************************************************************/

public class Main {
    public static <T extends Number> Double average(final T p_num1, final T p_num2) {
        if (p_num1 == null) {
            return p_num2 == null ? null : p_num2.doubleValue();
        }

        if (p_num2 == null) {
            return p_num1.doubleValue();
        }

        return (p_num1.doubleValue() + p_num2.doubleValue()) / 2.0;
    }
}

Related

  1. average(double[] values)
  2. average(final double[] values)
  3. average(final Float... values)
  4. average(final float[] values)
  5. average(final int totalAmount, final int orderCount)
  6. average(float[][] data, int startIndex, int endIndex)
  7. average(float[][] originalValues, float[][] newValues, int[] indexArray)
  8. average(int argb0, int argb1)
  9. average(int... is)