diff options
author | Godin <mandrikov@gmail.com> | 2010-11-03 16:34:10 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-11-03 16:34:10 +0000 |
commit | 72864ce12eeb02dc9d199ee0edb4d62a4bb33240 (patch) | |
tree | 0c2471e8ff624193c9100a3b4339c5df146e6e2e /sonar-plugin-api | |
parent | db1aa08abd0210d57d9f412eb1532f98d03cc08a (diff) | |
download | sonarqube-72864ce12eeb02dc9d199ee0edb4d62a4bb33240.tar.gz sonarqube-72864ce12eeb02dc9d199ee0edb4d62a4bb33240.zip |
Improve routines for patterns, add unit tests
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java | 12 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java | 12 |
2 files changed, 22 insertions, 2 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java index 2045b92faa2..572d2c1d01b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java @@ -80,6 +80,18 @@ public class WildcardPattern { return StringUtils.removeEnd(patternStr, "/"); } + /** + * @since 2.4 + */ + public static boolean match(WildcardPattern[] patterns, String value) { + for (WildcardPattern pattern : patterns) { + if (pattern.match(value)) { + return true; + } + } + return false; + } + public static WildcardPattern create(String pattern) { return create(pattern, "/"); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java index 1b0d6b80a2b..f57aff8f6e2 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java @@ -19,11 +19,11 @@ */ package org.sonar.api.utils; +import org.junit.Test; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import org.junit.Test; - public class WildcardPatternTest { private boolean match(String pattern, String value, String separator) { @@ -99,4 +99,12 @@ public class WildcardPatternTest { assertTrue(match("**", "java/io/Reader")); } + + @Test + public void multiplePatterns() { + WildcardPattern[] patterns = new WildcardPattern[] { WildcardPattern.create("Foo"), WildcardPattern.create("Bar") }; + assertTrue(WildcardPattern.match(patterns, "Foo")); + assertTrue(WildcardPattern.match(patterns, "Bar")); + assertFalse(WildcardPattern.match(patterns, "Other")); + } } |