From 8b47dde69313b7acf6752d9a03cf6f94a6b83c64 Mon Sep 17 00:00:00 2001 From: "Tomasz.Skowronski" Date: Sun, 25 Jun 2017 16:24:01 +0200 Subject: [PATCH] add jitpack badge readme typos --- README.md | 63 +++++++++++++++++++++-------------------------- pom.xml | 73 +++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index b69af64..3ae598a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![](https://jitpack.io/v/mortezaadi/bigdecimal-utils.svg)](https://jitpack.io/#mortezaadi/bigdecimal-utils) + BigDecimal Utils =============================================== Comparing BigDecimal is always hard to read and so error prone. I wrote this library @@ -10,18 +12,14 @@ Money somewhere in your code, you probably faced comparing two BigDecimals a lot What's wrong with BigDecimal comparison -------------------------------------- -Well, First of all you should know that if you use **equal** method of BigDecimal to compare two objects they only considered equal if they are equal in value and scale thus 2.0 is not equal to 2.00 when compared by -**equal** method. refer to JavaDocs. +Well, first of all you should know that if you use **equal** method of BigDecimal to compare two objects they only considered equal if they are equal in value and scale thus 2.0 is not equal to 2.00 when compared by +**equal** method refer to JavaDocs. To compare BigDecimal without considering their scale we should use **compareTo** method. So, probably this is the most common way to compare two BigDecimals. However it is so error prone and lacks readability. to feel what it looks like take a look at this line of code : - if(balance.compareTo(amount) < 0) && amount.compareTo(minAmount) >= 0)) { - // .... - }else { - // ... - } + return balance.compareTo(amount) < 0) && amount.compareTo(minAmount) >= 0)); the code above try to check condition "balance < amount && amount >= minAmount". You definitely spotted the problem. But how to solve this? @@ -32,51 +30,46 @@ BigDecimalUtils is a simple library to make comparing BigDecimal more readable a see the same comparison rewritten with this library import static ir.cafebabe.math.utils.BigDecimalUtils.*; - .. - .. - .. - .. - if( is(balance).lt(amount) && is(amount).gte(minAmount) ) { - // .... - }else { - // ... - } + + // ... + + return is(balance).lt(amount) && is(amount).gte(minAmount)); **Other methods in this library:** - is(bigdecimal).eq(four); //Equal - is(bigdecimal).gt(two); //Greater than - is(bigdecimal).gte(one); //Greater than equal - is(bigdecimal).lt(two); //Less than - is(bigdecimal).lte(two); //Less than equal + is(bigdecimal).eq(four); // equal + is(bigdecimal).gt(two); // greater than + is(bigdecimal).gte(one); // greater than equal + is(bigdecimal).lt(two); // less than + is(bigdecimal).lte(two); // less than equal - is(bigdecimal).notEq(four); //Not Equal - is(bigdecimal).notGt(two); //Not Greater than - is(bigdecimal).notGte(one); //Not Greater than equal - is(bigdecimal).notLt(two); //Not Less than - is(bigdecimal).notLte(two); //Not Less than equal + is(bigdecimal).notEq(four); // not equal + is(bigdecimal).notGt(two); // not greater than + is(bigdecimal).notGte(one); // not greater than equal + is(bigdecimal).notLt(two); // not less than + is(bigdecimal).notLte(two); // not less than equal is(bigdecimal).isZero(); is(bigdecimal).notZero(); is(bigdecimal).isPositive(); // greater than zero is(bigdecimal).isNegetive(); // less than zero - is(bigdecimal).isNonPositive(); //less than or equal zero - is(bigdecimal).isNonNegetive(); //greater than or equal zero + is(bigdecimal).isNonPositive(); // less than or equal zero + is(bigdecimal).isNonNegetive(); // greater than or equal zero - is(bigdecimal).isNullOrZero(); //is null or zero - is(bigdecimal).notNullOrZero(); //not null or zero + is(bigdecimal).isNullOrZero(); // is null or zero + is(bigdecimal).notNullOrZero(); // not null or zero -You can also compare a BigDecimal to other numerical values. for instance instead of writing +You can also compare a BigDecimal to other numerical values. For instance instead of writing is(bigdecimal).notEq(BigDecimal.valueOf(4)); -you can simply write: +you can simply and interchangeably write: is(bigdecimal).notEq(4); - is(bigdecimal).notEq(4L); //or - is(bigdecimal).notEq(4D); //or + is(bigdecimal).notEq(4L); + is(bigdecimal).notEq(4D); -PS +Why BigDecimal Utils? -------------------------- I didn't find any library to handle BigDecimal comparison. If you found one please let me know. diff --git a/pom.xml b/pom.xml index acad4fd..4d40cda 100644 --- a/pom.xml +++ b/pom.xml @@ -1,14 +1,61 @@ - - 4.0.0 - ir.cafebabe.math.utils - bigdecimal-utils - 0.0.1-SNAPSHOT - - - junit - junit - 4.12 - test - - + + 4.0.0 + ir.cafebabe.math.utils + bigdecimal-utils + 0.0.1-SNAPSHOT + + + true + + + + + junit + junit + 4.12 + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.2 + + 1.5 + 1.5 + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + \ No newline at end of file