branch develop updated (fa07d0b -> e46e40c)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository nuiton-utils. See http://git.nuiton.org/nuiton-utils.git from fa07d0b [jgitflow-maven-plugin]Updating develop poms back to pre merge state new 9b2ffe0 Generation d'un jar avec ses dépendances new 679c15e Add more methods to NumberUtil (See #3861) new e46e40c Fixes #3861 Merge branch 'feature/3861' into develop The 3 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit e46e40cb93dfec28af247133de01318f89b6dc24 Merge: 9b2ffe0 679c15e Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Jan 9 10:43:16 2016 +0100 Fixes #3861 Merge branch 'feature/3861' into develop commit 679c15ed23c1db809fdffea2546da88d06434f1f Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Jan 9 10:42:36 2016 +0100 Add more methods to NumberUtil (See #3861) commit 9b2ffe052e41a517dd52f2f31a0e1f46f573e8a7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Dec 18 22:00:58 2015 +0100 Generation d'un jar avec ses dépendances Summary of changes: pom.xml | 18 ++++ src/main/java/org/nuiton/util/NumberUtil.java | 102 +++++++++++++++++++++- src/test/java/org/nuiton/util/NumberUtilTest.java | 49 +++++++++++ 3 files changed, 167 insertions(+), 2 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-utils. See http://git.nuiton.org/nuiton-utils.git commit 9b2ffe052e41a517dd52f2f31a0e1f46f573e8a7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Dec 18 22:00:58 2015 +0100 Generation d'un jar avec ses dépendances --- pom.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pom.xml b/pom.xml index d1771b4..3ead646 100644 --- a/pom.xml +++ b/pom.xml @@ -258,6 +258,24 @@ </execution> </executions> </plugin> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <id>build-jar-with-dependencies</id> + <goals> + <goal>single</goal> + </goals> + <phase>package</phase> + <configuration> + <attach>true</attach> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + </configuration> + </execution> + </executions> + </plugin> </plugins> </build> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-utils. See http://git.nuiton.org/nuiton-utils.git commit 679c15ed23c1db809fdffea2546da88d06434f1f Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Jan 9 10:42:36 2016 +0100 Add more methods to NumberUtil (See #3861) --- src/main/java/org/nuiton/util/NumberUtil.java | 102 +++++++++++++++++++++- src/test/java/org/nuiton/util/NumberUtilTest.java | 49 +++++++++++ 2 files changed, 149 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/nuiton/util/NumberUtil.java b/src/main/java/org/nuiton/util/NumberUtil.java index 9ac9c55..aabc905 100644 --- a/src/main/java/org/nuiton/util/NumberUtil.java +++ b/src/main/java/org/nuiton/util/NumberUtil.java @@ -22,6 +22,12 @@ package org.nuiton.util; * #L% */ +import com.google.common.base.Predicate; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.math.BigDecimal; +import java.math.MathContext; import java.util.Arrays; /** @@ -31,13 +37,18 @@ import java.util.Arrays; public class NumberUtil { /** + * Logger. + */ + private static final Log log = LogFactory.getLog(NumberUtil.class); + + /** * Divide the divisor by the dividend. * Returns an array containing the quotients rounded up or down * to ensure the sum of the quotients equals the divisor. - * + * <p> * e.g. divideAndEnsureSum(100, 3) returns {34, 33, 33} * - * @param divisor the divisor + * @param divisor the divisor * @param dividend the dividend * @return an array whose length equals dividend */ @@ -61,4 +72,91 @@ public class NumberUtil { return result; } + + public static final Predicate<Integer> NULL_OR_ZERO_INTEGER = new Predicate<Integer>() { + + @Override + public boolean apply(Integer input) { + return input == null || input == 0; + } + }; + + public static final Predicate<Float> NULL_OR_ZERO_FLOAT_ONE_DIGIT = new Predicate<Float>() { + + @Override + public boolean apply(Float input) { + return input == null || Math.abs(roundOneDigit(input)) < 0.1; + } + }; + public static final Predicate<Float> NULL_OR_ZERO_FLOAT_TWO_DIGITS = new Predicate<Float>() { + + @Override + public boolean apply(Float input) { + return input == null || Math.abs(roundTwoDigits(input)) < 0.01; + } + }; + public static final Predicate<Float> NULL_OR_ZERO_FLOAT_THREE_DIGITS = new Predicate<Float>() { + + @Override + public boolean apply(Float input) { + return input == null || Math.abs(roundThreeDigits(input)) < 0.001; + } + }; + public static final Predicate<Float> NULL_OR_ZERO_FLOAT_FOUR_DIGITS = new Predicate<Float>() { + + @Override + public boolean apply(Float input) { + return input == null || Math.abs(roundFourDigits(input)) < 0.0001; + } + }; + + public static final Predicate<Float> NULL_OR_ZERO_FLOAT_FIVE_DIGITS = new Predicate<Float>() { + + @Override + public boolean apply(Float input) { + return input == null || Math.abs(roundFiveDigits(input)) < 0.00001; + } + }; + + protected static final MathContext mc1Digit = new MathContext(1); + protected static final MathContext mc2Digits = new MathContext(2); + protected static final MathContext mc3Digits = new MathContext(3); + protected static final MathContext mc4Digits = new MathContext(4); + protected static final MathContext mc5Digits = new MathContext(5); + + public static Float roundOneDigit(Float number) { + return round(number, mc1Digit); + } + + public static Float roundTwoDigits(Float number) { + return round(number, mc2Digits); + } + + public static Float roundThreeDigits(Float number) { + return round(number, mc3Digits); + } + + public static Float roundFourDigits(Float number) { + return round(number, mc4Digits); + } + + public static Float roundFiveDigits(Float number) { + return round(number, mc5Digits); + } + + public static Float roundNDigits(Float number, int digits) { + return round(number, new MathContext(digits)); + } + + public static Float round(Float number, MathContext mc) { + float old = number; + float partieEntier = (int) old; + float digit = old - (int) old; + number = partieEntier + new BigDecimal(digit).round(mc).floatValue(); + if (log.isDebugEnabled()) { + log.debug("round " + old + " to " + number + " with mc = " + mc); + } + return number; + } + } diff --git a/src/test/java/org/nuiton/util/NumberUtilTest.java b/src/test/java/org/nuiton/util/NumberUtilTest.java index 44bc78d..00d51d3 100644 --- a/src/test/java/org/nuiton/util/NumberUtilTest.java +++ b/src/test/java/org/nuiton/util/NumberUtilTest.java @@ -43,4 +43,53 @@ public class NumberUtilTest { Assert.assertArrayEquals(new int[]{ 17, 17, 17, 17, 16, 16 }, NumberUtil.divideAndEnsureSum(100, 6)); } + @Test + public void testRound3Digits() { + + assertRoundThreeDigits(1.2f, 1.2f); + assertRoundThreeDigits(1.22f, 1.22f); + assertRoundThreeDigits(1.222f, 1.222f); + assertRoundThreeDigits(1.2222f, 1.222f); + assertRoundThreeDigits(1.2225f, 1.222f); + assertRoundThreeDigits(1.2226f, 1.223f); + assertRoundThreeDigits(11.2226f, 11.223f); + assertRoundThreeDigits(111.2226f, 111.223f); + assertRoundThreeDigits(1111.2226f, 1111.223f); + + assertRoundThreeDigits(1111.999f, 1111.999f); + assertRoundThreeDigits(1111.9994f, 1111.999f); + assertRoundThreeDigits(1111.9995f, 1112f); + assertRoundThreeDigits(1111.9996f, 1112f); + } + + @Test + public void testRoundOneDigit() { + + assertRoundOneDigit(1.2f, 1.2f); + assertRoundOneDigit(1.22f, 1.2f); + assertRoundOneDigit(1.5f, 1.5f); + assertRoundOneDigit(1.55f, 1.5f); + assertRoundOneDigit(1.56f, 1.6f); + assertRoundOneDigit(1.9f, 1.9f); + assertRoundOneDigit(1.222f, 1.2f); + assertRoundOneDigit(11.2226f, 11.2f); + assertRoundOneDigit(111.2226f, 111.2f); + assertRoundOneDigit(1111.2226f, 1111.2f); + + assertRoundOneDigit(1111.999f, 1112.0f); + assertRoundOneDigit(1111.9994f, 1112.0f); + assertRoundOneDigit(1111.9995f, 1112.0f); + assertRoundOneDigit(1111.9996f, 1112.0f); + } + + protected void assertRoundThreeDigits(float number, float expected) { + float actual = NumberUtil.roundThreeDigits(number); + Assert.assertEquals("" + expected, "" + actual); + } + + protected void assertRoundOneDigit(float number, float expected) { + Float actual = NumberUtil.roundOneDigit(number); + Assert.assertEquals("" + expected, "" + actual); + } + } -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-utils. See http://git.nuiton.org/nuiton-utils.git commit e46e40cb93dfec28af247133de01318f89b6dc24 Merge: 9b2ffe0 679c15e Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Jan 9 10:43:16 2016 +0100 Fixes #3861 Merge branch 'feature/3861' into develop src/main/java/org/nuiton/util/NumberUtil.java | 102 +++++++++++++++++++++- src/test/java/org/nuiton/util/NumberUtilTest.java | 49 +++++++++++ 2 files changed, 149 insertions(+), 2 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm