Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add .isZero() comparison #13

Open
alensiljak opened this issue Oct 14, 2015 · 1 comment
Open

add .isZero() comparison #13

alensiljak opened this issue Oct 14, 2015 · 1 comment

Comments

@alensiljak
Copy link

Hi,

Checking whether an amount is zero, negative, or positive is quite a common usage scenario and adding helper methods would make this check much easier.
Currently we have to create a zero object and compare the actual value with this.
JavaMoney has some great comparators, like .isZero(), isZeroOrNegative(), etc. (https://github.com/JavaMoney/jsr354-ri/blob/master/src/main/java/org/javamoney/moneta/FastMoney.java)
Would be great if Money type had something similar built in.

i.e.

@Override
    public boolean isZero() {
        return this.number == 0L;
    }

    @Override
    public boolean isPositive() {
        return this.number > 0L;
    }

    @Override
    public boolean isPositiveOrZero() {
        return this.number >= 0L;
    }

    @Override
    public boolean isNegative() {
        return this.number < 0L;
    }

    @Override
    public boolean isNegativeOrZero() {
        return this.number <= 0L;
    }

BigDecimal implementation is using .signum().
https://github.com/JavaMoney/jsr354-ri/blob/master/src/main/java/org/javamoney/moneta/Money.java

alensiljak pushed a commit to alensiljak/money-conversion that referenced this issue Oct 14, 2015
@ratcashdev
Copy link

You may want to consider using SIGNUM.
More details here: alensiljak@97dabbf#commitcomment-29308125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants