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

brooklyn.util.math.MathFunctions Maven / Gradle / Ivy

Go to download

Utility classes and methods developed for Brooklyn but not dependendent on Brooklyn or much else

There is a newer version: 0.7.0-M1
Show newest version
package brooklyn.util.math;

import javax.annotation.Nullable;

import com.google.common.base.Function;

public class MathFunctions {

    public static Function plus(final int addend) {
        return new Function() {
            public Integer apply(@Nullable Integer input) {
                if (input==null) return null;
                return input.intValue() + addend;
            }
        };
    }

    public static Function plus(final double addend) {
        return new Function() {
            public Double apply(@Nullable Double input) {
                if (input==null) return null;
                return input.doubleValue() + addend;
            }
        };
    }

    public static Function times(final int multiplicand) {
        return new Function() {
            public Integer apply(@Nullable Integer input) {
                if (input==null) return null;
                return input.intValue() * multiplicand;
            }
        };
    }

    public static Function times(final double multiplicand) {
        return new Function() {
            public Double apply(@Nullable Double input) {
                if (input==null) return null;
                return input.doubleValue() * multiplicand;
            }
        };
    }

    public static Function divide(final double divisor) {
        return new Function() {
            public Double apply(@Nullable Number input) {
                if (input==null) return null;
                return input.doubleValue() / divisor;
            }
        };
    }

    public static  Function divide(final Function input, final double divisor) {
        return new Function() {
            public Double apply(@Nullable T input2) {
                Number n = input.apply(input2);
                if (n==null) return null;
                return n.doubleValue() / divisor;
            }
        };
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy