brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [2/6] brooklyn-server git commit: more conveniences for Strings
Date Mon, 07 Nov 2016 15:17:08 GMT
more conveniences for Strings


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/dc52db3f
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/dc52db3f
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/dc52db3f

Branch: refs/heads/master
Commit: dc52db3fc6030dc8e863d6c71794ac7d0bcf732b
Parents: 4d1e3f3
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Nov 7 11:16:56 2016 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Nov 7 11:22:59 2016 +0000

----------------------------------------------------------------------
 .../org/apache/brooklyn/util/text/Strings.java     | 17 ++++++++++++++++-
 .../org/apache/brooklyn/util/text/StringsTest.java |  8 ++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/dc52db3f/utils/common/src/main/java/org/apache/brooklyn/util/text/Strings.java
----------------------------------------------------------------------
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 b9168cc..22a4f7c 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
@@ -41,8 +41,10 @@ import com.google.common.base.Functions;
 import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
 import com.google.common.base.Supplier;
 import com.google.common.base.Suppliers;
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Ordering;
 
 public class Strings {
@@ -217,7 +219,19 @@ public class Strings {
 
     /** convenience for joining lines together */
     public static String lines(String ...lines) {
-        return Joiner.on("\n").join(Arrays.asList(lines));
+        if (lines==null) return null;
+        return lines(Arrays.asList(lines));
+    }
+    
+    /** convenience for joining lines together */
+    public static String lines(Iterable<String> lines) {
+        if (lines==null) return null;
+        return Joiner.on("\n").join(lines);
+    }
+
+    public static String removeLines(String multiline, Predicate<CharSequence> patternToRemove)
{
+        if (multiline==null) return null;
+        return lines(Iterables.filter(Arrays.asList(multiline.split("\n")), Predicates.not(patternToRemove)));
     }
 
     /** NON-REGEX - replaces all key->value entries from the replacement map in source
(non-regex) */
@@ -948,4 +962,5 @@ public class Strings {
         }
         return result;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/dc52db3f/utils/common/src/test/java/org/apache/brooklyn/util/text/StringsTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/text/StringsTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/text/StringsTest.java
index c3f6d92..3ca7663 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/text/StringsTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/text/StringsTest.java
@@ -343,6 +343,14 @@ public class StringsTest extends FixedLocaleTest {
         Assert.assertEquals(Strings.maxlenWithEllipsis("hello world", 9), "hello ...");
         Assert.assertEquals(Strings.maxlenWithEllipsis("hello world", 7, "--"), "hello--");
     }
+    
+    public void testLines() {
+        Assert.assertEquals(Strings.lines("a", "b"), "a\nb");
+    }
+    
+    public void testRemoveLines() {
+        Assert.assertEquals(Strings.removeLines(Strings.lines("a", "b"), StringPredicates.containsLiteralIgnoreCase("A")),
"b");
+    }
 
     @Test
     public void testGetRemainderOfLineAfter() {


Mime
View raw message