Here you can find the source of coalesce(float... p)
Parameter | Description |
---|---|
p | array of at least unit length |
public static float coalesce(float... p)
//package com.java2s; /*//from www . j a v a2 s .c o m * Copyright (c) 2016 Fraunhofer IGD * * All rights reserved. This program and the accompanying materials are made * available under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution. If not, see <http://www.gnu.org/licenses/>. * * Contributors: * Fraunhofer IGD <http://www.igd.fraunhofer.de/> */ public class Main { /** * SQL-like coalescing using isReal() * * @param p array of at least unit length * @return the first real value from the given array */ public static float coalesce(float... p) { for (float v : p) { if (isReal(v)) { return v; } } return p[p.length - 1]; } /** * Checks if a floating point number is real (not infinite and not NaN) * * @param x the number to check * @return true if x is real, false otherwise */ public static boolean isReal(float x) { return (!Float.isInfinite(x) && !Float.isNaN(x)); } /** * Checks if a floating point number is real (not infinite and not NaN) * * @param x the number to check * @return true if x is real, false otherwise */ public static boolean isReal(double x) { return (!Double.isInfinite(x) && !Double.isNaN(x)); } }