This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
The following commit(s) were added to refs/heads/master by this push: new 3deb69f856 tidy utility methods, support floor/ceil 3deb69f856 is described below commit 3deb69f856696c17f7df97d7a47118e1b31ba3e3 Author: Alex Heneveld <a...@cloudsoft.io> AuthorDate: Fri Apr 19 16:57:47 2024 +0100 tidy utility methods, support floor/ceil --- .../src/main/java/org/apache/brooklyn/util/math/NumberMath.java | 4 ++++ .../common/src/main/java/org/apache/brooklyn/util/text/Strings.java | 5 ++++- utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/math/NumberMath.java b/utils/common/src/main/java/org/apache/brooklyn/util/math/NumberMath.java index eb2b2f2d97..374885bcdd 100644 --- a/utils/common/src/main/java/org/apache/brooklyn/util/math/NumberMath.java +++ b/utils/common/src/main/java/org/apache/brooklyn/util/math/NumberMath.java @@ -165,6 +165,10 @@ public class NumberMath<T extends Number> { } public T abs() { return attemptUnary(x -> x<0 ? -x : x, x -> x<0 ? -x : x, BigInteger::abs, BigDecimal::abs); } + public T round() { return attemptUnary(x -> x, d -> (double) Math.round(d), x -> x, x -> x.setScale(0, BigDecimal.ROUND_DOWN)); } + public T ceil() { return attemptUnary(x -> x, d -> Math.ceil(d), x -> x, x -> x.setScale(0, BigDecimal.ROUND_CEILING)); } + public T floor() { return attemptUnary(x -> x, d -> Math.floor(d), x -> x, x -> x.setScale(0, BigDecimal.ROUND_FLOOR)); } + public T frac() { return attemptUnary(x -> 0L, d -> d - Math.floor(d), x -> BigInteger.ZERO, x -> x.subtract(x.setScale(0, BigDecimal.ROUND_FLOOR))); } public T negate() { return attemptUnary(x -> -x, x -> -x, BigInteger::negate, BigDecimal::negate); } public T add(T rhs) { return attemptBinary(rhs, (x,y) -> x+y, (x,y) -> x+y, BigInteger::add, BigDecimal::add); } diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/text/Strings.java b/utils/common/src/main/java/org/apache/brooklyn/util/text/Strings.java index d3af722ac4..f48f1f4302 100644 --- a/utils/common/src/main/java/org/apache/brooklyn/util/text/Strings.java +++ b/utils/common/src/main/java/org/apache/brooklyn/util/text/Strings.java @@ -1057,8 +1057,11 @@ public class Strings { /** prefixes every line in `body` (second argument) by the given string (first argument) */ public static String prefixAddedToEachLine(String prefix, String body) { + return prefixAddedToEachLine(prefix, body, false); + } + public static String prefixAddedToEachLine(String prefix, String body, boolean includeTrailingEmptyLines) { if (body==null) return null; - return Arrays.stream(body.split("\n")).map(s -> prefix + s).collect(Collectors.joining("\n")); + return Arrays.stream(body.split("\n", includeTrailingEmptyLines ? -1 : 0)).map(s -> prefix + s).collect(Collectors.joining("\n")); } public static boolean containsLiteralAsWord(String context, String word) { diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java b/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java index fd1083e5f5..7b996bdac1 100644 --- a/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java +++ b/utils/common/src/main/java/org/apache/brooklyn/util/time/Time.java @@ -75,7 +75,7 @@ public class Time { return makeDateString(System.currentTimeMillis()); } - /** as {@link #makeDateString(Date)} for long millis since UTC epock */ + /** as {@link #makeDateString(Date)} for long millis since UTC epoch */ public static String makeDateString(long date) { return makeDateString(new Date(date), DATE_FORMAT_PREFERRED); }