package eu.svjatoslav.commons.network.navigation;
-import eu.svjatoslav.commons.string.WildCardMatcher;
+import eu.svjatoslav.commons.string.GlobMatcher;
import java.util.ArrayList;
import java.util.List;
}
public boolean matchesUrl(final String url) {
- return WildCardMatcher.match(url, pattern);
+ return GlobMatcher.match(url, pattern);
}
public NavigationItem getDefaultNavigationItem() {
--- /dev/null
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.commons.string;
+
+public class GlobMatcher {
+
+ /**
+ * Allow only for * in wildcards
+ */
+ private static boolean checkWildCardEnd(final String wildcardExpression,
+ int wildCardPosition) {
+ for (; wildCardPosition < wildcardExpression.length(); wildCardPosition++) {
+ final char wildCardChar = wildcardExpression
+ .charAt(wildCardPosition);
+ if (wildCardChar != '*')
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * <pre>
+ * Test input string against wildcard expression.
+ * * -- corresponds to any amount of characters.
+ * ? -- corresponds to any single character.
+ * </pre>
+ *
+ * @param inputString input string
+ * @param wildcardExpression wildcard expression
+ * @return <code>true</code> if input string matches input pattern
+ */
+ public static boolean match(final String inputString,
+ final String wildcardExpression) {
+
+ if (inputString == null)
+ return false;
+
+ if (wildcardExpression == null)
+ return false;
+
+ int i;
+
+ for (i = 0; i < inputString.length(); i++) {
+ if (i >= wildcardExpression.length())
+ return false;
+ final char wildCardChar = wildcardExpression.charAt(i);
+ if (wildCardChar == '*')
+ return matchPiece(inputString, i, wildcardExpression, i + 1);
+ if (wildCardChar != '?')
+ if (inputString.charAt(i) != wildCardChar)
+ return false;
+ }
+
+ return checkWildCardEnd(wildcardExpression, i);
+ }
+
+ private static boolean matchPiece(final String inputString,
+ final int inputStringIndex, final String wildcardExpression,
+ final int wildCardExpressionIndex) {
+
+ int wildCardPosition = wildCardExpressionIndex;
+
+ for (int i = inputStringIndex; i < inputString.length(); i++) {
+
+ wildCardPosition = wildCardExpressionIndex;
+
+ subMatchAttempt:
+ {
+
+ for (int j = i; j < inputString.length(); j++) {
+ if (wildCardPosition >= wildcardExpression.length())
+ break subMatchAttempt;
+ final char wildCardChar = wildcardExpression
+ .charAt(wildCardPosition);
+
+ if (wildCardChar == '*')
+ return matchPiece(inputString, j, wildcardExpression,
+ wildCardPosition + 1);
+
+ if (wildCardChar != '?')
+ if (inputString.charAt(j) != wildCardChar)
+ break subMatchAttempt;
+
+ wildCardPosition++;
+ }
+
+ return checkWildCardEnd(wildcardExpression, wildCardPosition);
+ }
+
+ }
+
+ return checkWildCardEnd(wildcardExpression, wildCardPosition);
+ }
+
+}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality.
- * Copyright ©2012-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.commons.string;
-
-public class WildCardMatcher {
-
- /**
- * Allow only for * in wildcards
- */
- private static boolean checkWildCardEnd(final String wildcardExpression,
- int wildCardPosition) {
- for (; wildCardPosition < wildcardExpression.length(); wildCardPosition++) {
- final char wildCardChar = wildcardExpression
- .charAt(wildCardPosition);
- if (wildCardChar != '*')
- return false;
- }
-
- return true;
- }
-
- /**
- * <pre>
- * Test input string against wildcard expression.
- * * -- corresponds to any amount of characters.
- * ? -- corresponds to any single character.
- * </pre>
- *
- * @param inputString input string
- * @param wildcardExpression wildcard expression
- * @return <code>true</code> if input string matches input pattern
- */
- public static boolean match(final String inputString,
- final String wildcardExpression) {
-
- if (inputString == null)
- return false;
-
- if (wildcardExpression == null)
- return false;
-
- int i;
-
- for (i = 0; i < inputString.length(); i++) {
- if (i >= wildcardExpression.length())
- return false;
- final char wildCardChar = wildcardExpression.charAt(i);
- if (wildCardChar == '*')
- return matchPiece(inputString, i, wildcardExpression, i + 1);
- if (wildCardChar != '?')
- if (inputString.charAt(i) != wildCardChar)
- return false;
- }
-
- return checkWildCardEnd(wildcardExpression, i);
- }
-
- private static boolean matchPiece(final String inputString,
- final int inputStringIndex, final String wildcardExpression,
- final int wildCardExpressionIndex) {
-
- int wildCardPosition = wildCardExpressionIndex;
-
- for (int i = inputStringIndex; i < inputString.length(); i++) {
-
- wildCardPosition = wildCardExpressionIndex;
-
- subMatchAttempt:
- {
-
- for (int j = i; j < inputString.length(); j++) {
- if (wildCardPosition >= wildcardExpression.length())
- break subMatchAttempt;
- final char wildCardChar = wildcardExpression
- .charAt(wildCardPosition);
-
- if (wildCardChar == '*')
- return matchPiece(inputString, j, wildcardExpression,
- wildCardPosition + 1);
-
- if (wildCardChar != '?')
- if (inputString.charAt(j) != wildCardChar)
- break subMatchAttempt;
-
- wildCardPosition++;
- }
-
- return checkWildCardEnd(wildcardExpression, wildCardPosition);
- }
-
- }
-
- return checkWildCardEnd(wildcardExpression, wildCardPosition);
- }
-
-}
--- /dev/null
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.commons.string;
+
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class GlobMatcherTest {
+
+
+ private static void testWildcard(final String string, final String pattern,
+ final boolean expectedResult) {
+
+ final boolean result = GlobMatcher.match(string, pattern);
+
+ if (result != expectedResult)
+ fail("Wildcard match failed.");
+
+ }
+
+ @Test
+ public void test() {
+
+ testWildcard("IMG_9770.JPG", "*.J*", true);
+ testWildcard("1", "1", true);
+ testWildcard("1", "*", true);
+ testWildcard("f", "1", false);
+ testWildcard("Hello !", "Hell*!***", true);
+ testWildcard("Hello !", "Hell*!", true);
+ testWildcard("Hello !", "Hell*", true);
+ testWildcard("Hello !", "Hell", false);
+ testWildcard("Hello !", "* *", true);
+
+ }
+
+}
+++ /dev/null
-/*
- * Svjatoslav Commons - shared library of common functionality.
- * Copyright ©2012-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.commons.string;
-
-import org.junit.Test;
-
-import static org.junit.Assert.fail;
-
-public class WildCardMatcherTest {
-
-
- private static void testWildcard(final String string, final String pattern,
- final boolean expectedResult) {
-
- final boolean result = WildCardMatcher.match(string, pattern);
-
- if (result != expectedResult)
- fail("Wildcard match failed.");
-
- }
-
- @Test
- public void test() {
-
- testWildcard("IMG_9770.JPG", "*.J*", true);
- testWildcard("1", "1", true);
- testWildcard("1", "*", true);
- testWildcard("f", "1", false);
- testWildcard("Hello !", "Hell*!***", true);
- testWildcard("Hello !", "Hell*!", true);
- testWildcard("Hello !", "Hell*", true);
- testWildcard("Hello !", "Hell", false);
- testWildcard("Hello !", "* *", true);
-
- }
-
-}