All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.heigit.bigspatialdata.oshdb.api.generic.NumberUtils Maven / Gradle / Ivy

package org.heigit.bigspatialdata.oshdb.api.generic;

import java.io.Serializable;
import org.jetbrains.annotations.NotNull;

public class NumberUtils implements Serializable {
  /**
   * Add two numeric values and return the sum in the smallest common type.
   *
   * 

Supports Integer, Float and Double values

* * @param x a numeric value * @param y a numeric value * @param a numeric data type * @return the sum of x and y */ @NotNull public static T add(T x, T y) { if (x instanceof Integer && y instanceof Integer) { return (T) (Integer) (x.intValue() + y.intValue()); } else if (x instanceof Float && (y instanceof Float || y instanceof Integer)) { return (T) (Float) (x.floatValue() + y.floatValue()); } else { return (T) (Double) (x.doubleValue() + y.doubleValue()); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy