diff --git a/README.md b/README.md
index 27d9658..cd8918c 100644
--- a/README.md
+++ b/README.md
@@ -107,6 +107,6 @@ Just add this to your **pom.xml**
com.hijackermax
utils
- 0.1.0
+ 0.1.2
```
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 5a75032..73231e0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.hijackermax
utils
- 0.1.0
+ 0.1.2
utils
A set of utils that can help in app development
diff --git a/src/main/java/com/hijackermax/utils/lang/FunctionalUtils.java b/src/main/java/com/hijackermax/utils/lang/FunctionalUtils.java
index c215503..375c5f5 100644
--- a/src/main/java/com/hijackermax/utils/lang/FunctionalUtils.java
+++ b/src/main/java/com/hijackermax/utils/lang/FunctionalUtils.java
@@ -16,7 +16,7 @@ private FunctionalUtils() {
}
/**
- * Provides wrapper {@link Consumer} which cathes {@link Exception} thrown by the input value {@link Consumer}
+ * Provides wrapper {@link Consumer} which catches {@link Exception} thrown by the input value {@link Consumer}
* and supplies it to provided exception{@link BiConsumer}
*
* @param consumer value {@link Consumer} that can throw {@link Exception}
@@ -36,7 +36,7 @@ public static Consumer failSafeStrategy(Consumer consumer, BiConsumer<
}
/**
- * Cathes {@link Exception} thrown by provided {@link Runnable} and supplies it to provided exception{@link Consumer}
+ * Catches {@link Exception} thrown by provided {@link Runnable} and supplies it to provided exception{@link Consumer}
*
* @param runnable {@link Runnable} that can throw {@link Exception}
* @param exceptionConsumer thrown {@link Exception} {@link Consumer}
@@ -52,7 +52,7 @@ public static void failSafeStrategy(Runnable runnable,
}
/**
- * Provides wrapper {@link Callable} which cathes {@link Exception} thrown by the provided {@link Callable}
+ * Provides wrapper {@link Callable} which catches {@link Exception} thrown by the provided {@link Callable}
* and supplies it to provided exception{@link Consumer},
* in case of failure return invoke result of fallback {@link Supplier}
*
diff --git a/src/main/java/com/hijackermax/utils/lang/StringUtils.java b/src/main/java/com/hijackermax/utils/lang/StringUtils.java
index 8c25f23..18ccdc5 100644
--- a/src/main/java/com/hijackermax/utils/lang/StringUtils.java
+++ b/src/main/java/com/hijackermax/utils/lang/StringUtils.java
@@ -78,7 +78,7 @@ public final class StringUtils {
private static final Pattern WHITESPACES_PATTERN = Pattern.compile("\\s+");
private static final Pattern NON_DIGITS_PATTERN = Pattern.compile("[^\\d.]");
private static final Pattern DIGITS_PATTERN = Pattern.compile("[^\\D.]");
- private static final Pattern NAMED_FORMAT_PATTERN = Pattern.compile("(?iu)(?:\\$\\{(?:(\\w+)(?:\\?`([^`]+[\\p{Alnum}\\p{IsAlnum}\\p{Punct}\\p{IsPunct}']+[\\s]?[^`]+)`)?(%\\w+)?)\\})");
+ private static final Pattern NAMED_FORMAT_PATTERN = Pattern.compile("(?iu)(?:\\$\\{(?:(\\w+)(?:\\?`([^``]*|-|[^`]+[\\p{Alnum}\\p{IsAlnum}\\p{Punct}\\p{IsPunct}']+[\\s]?[^`]+)`)?(%\\w+)?)\\})");
private StringUtils() {
}
@@ -653,14 +653,14 @@ public static String notEmptyOrElse(String value, String defaultValue) {
* @param values {@link Map} of values that should replace tokens in provided template
* @return formatted string with provided values map,
* or empty string if provided template is empty or null,
- * or template if it is blank or values map is empty or null
+ * or template if it is blank or values map is null
* @since 0.1.0
*/
public static String namedFormat(String template, Map values) {
if (isEmpty(template)) {
return EMPTY;
}
- if (isBlank(template) || CollectionUtils.isEmpty(values)) {
+ if (isBlank(template) || Objects.isNull(values)) {
return template;
}
Transformer transformer = Transformer.of(template);
diff --git a/src/test/java/com/hijackermax/utils/lang/StringUtilsTest.java b/src/test/java/com/hijackermax/utils/lang/StringUtilsTest.java
index 3a9f162..db1f10c 100644
--- a/src/test/java/com/hijackermax/utils/lang/StringUtilsTest.java
+++ b/src/test/java/com/hijackermax/utils/lang/StringUtilsTest.java
@@ -441,12 +441,12 @@ void testNamedFormat() {
);
assertEquals("Foo bar: ff = 255 128 % Test", StringUtils.namedFormat(template, values));
- String spacesInDefault = "Foo ${text_default?` bar ?>`}: ${numeric%x} = ${numeric} ${numeric_default?`@[ 128]$^`%x} % ${text} ${missing}";
+ String spacesInDefault = "Foo ${text_default?` \\b-a-r/ ?>`}: ${numeric%x} = ${numeric} ${numeric_default?`@[ 128]$^`%x} % ${text} ${missing}";
Map values2 = Map.of(
"numeric", 255,
"text", "Test"
);
- assertEquals("Foo bar ?>: ff = 255 @[ 128]$^ % Test ${missing}", StringUtils.namedFormat(spacesInDefault, values2));
+ assertEquals("Foo \\b-a-r/ ?>: ff = 255 @[ 128]$^ % Test ${missing}", StringUtils.namedFormat(spacesInDefault, values2));
}
@Test
@@ -454,7 +454,9 @@ void testTransferValues() {
Pattern pattern = Pattern.compile("(?iu)(?:(\\$\\{(?\\w+)?\\})|(#\\{(?\\w+)?\\})|(%\\{(?\\w+)?\\}))");
assertEquals(StringUtils.EMPTY, StringUtils.transferValues(null, null, null));
assertEquals(StringUtils.EMPTY, StringUtils.transferValues(pattern, StringUtils.BLANK, StringUtils.BLANK));
- assertEquals("Foo ${value1} bar ${value2} ${value3} ${value4?`Test Test`}", StringUtils.transferValues(Pattern.compile(""), "Foo ${value_one} %{value_three}", "Foo ${value1} bar ${value2} ${value3} ${value4?`Test Test`}"));
+ assertEquals("Foo ${value1} bar ${value2} ${value3} Test Test", StringUtils.transferValues(Pattern.compile(""), "Foo ${value_one} %{value_three}", "Foo ${value1} bar ${value2} ${value3} ${value4?`Test Test`}"));
+ assertEquals("Foo ${value1} bar ${value2} ${value3} -", StringUtils.transferValues(Pattern.compile(""), "Foo ${value_one} %{value_three}", "Foo ${value1} bar ${value2} ${value3} ${value4?`-`}"));
+ assertEquals("Foo bar ${value2} ${value3} -", StringUtils.transferValues(Pattern.compile(""), "Foo ${value_one} %{value_three}", "Foo ${value1?``} bar ${value2} ${value3} ${value4?`-`}"));
assertEquals("Foo value_one bar value_two default", StringUtils.transferValues(pattern, "Foo ${value_one} #{value_two}", "Foo ${value1} bar ${value2} ${value4?`default`}"));
assertEquals("Foo value_one bar ${value2} value_three Test Test", StringUtils.transferValues(pattern, "Foo ${value_one} %{value_three}", "Foo ${value1} bar ${value2} ${value3} ${value4?`Test Test`}"));
}