/** * Checks if the monetary value is zero, treating null as zero. * <p> * This method accepts any implementation of {@code BigMoneyProvider}. * * @param moneyProvider the money to check, null returns zero * @return true if the money is null or zero */ public static boolean isZero(BigMoneyProvider moneyProvider) { return (moneyProvider == null || moneyProvider.toBigMoney().isZero()); }
/** * Checks if the monetary value is positive or zero, treating null as zero. * <p> * This method accepts any implementation of {@code BigMoneyProvider}. * * @param moneyProvider the money to check, null returns true * @return true if the money is null, zero or positive */ public static boolean isPositiveOrZero(BigMoneyProvider moneyProvider) { return (moneyProvider == null || moneyProvider.toBigMoney().isPositiveOrZero()); }
/** * Checks if the monetary value is negative or zero, treating null as zero. * <p> * This method accepts any implementation of {@code BigMoneyProvider}. * * @param moneyProvider the money to check, null returns true * @return true if the money is null, zero or negative */ public static boolean isNegativeOrZero(BigMoneyProvider moneyProvider) { return (moneyProvider == null || moneyProvider.toBigMoney().isNegativeOrZero()); }
/** * Checks if the monetary value is positive and non-zero, treating null as zero. * <p> * This method accepts any implementation of {@code BigMoneyProvider}. * * @param moneyProvider the money to check, null returns false * @return true if the money is non-null and positive */ public static boolean isPositive(BigMoneyProvider moneyProvider) { return (moneyProvider != null && moneyProvider.toBigMoney().isPositive()); }
/** * Checks if the monetary value is negative and non-zero, treating null as zero. * <p> * This method accepts any implementation of {@code BigMoneyProvider}. * * @param moneyProvider the money to check, null returns false * @return true if the money is non-null and negative */ public static boolean isNegative(BigMoneyProvider moneyProvider) { return (moneyProvider != null && moneyProvider.toBigMoney().isNegative()); }
/** * Obtains an instance of {@code BigMoney} from a provider. * <p> * This allows you to create an instance from any class that implements the * provider, such as {@code Money}. * This method simply calls {@link BigMoneyProvider#toBigMoney()} checking for nulls. * * @param moneyProvider the money to convert, not null * @return the new instance, never null */ public static BigMoney of(BigMoneyProvider moneyProvider) { MoneyUtils.checkNotNull(moneyProvider, "BigMoneyProvider must not be null"); BigMoney money = moneyProvider.toBigMoney(); MoneyUtils.checkNotNull(money, "BigMoneyProvider must not return null"); return money; }