You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/03/15 16:14:57 UTC

[GitHub] [incubator-seatunnel] CalvinKirs commented on a change in pull request #1442: [Improve][Config] Refactor StringTemplate to unify variables substitute util

CalvinKirs commented on a change in pull request #1442:
URL: https://github.com/apache/incubator-seatunnel/pull/1442#discussion_r827163386



##########
File path: seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/StringTemplate.java
##########
@@ -17,35 +17,17 @@
 
 package org.apache.seatunnel.common.utils;
 
-import org.apache.commons.lang3.text.StrSubstitutor;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
+/**
+ * please using {@link VariablesSubstitute} instead, since 2.0.5
+ */
+@Deprecated
 public final class StringTemplate {
 
     private StringTemplate() {
     }
 
-    /**
-     * @param str        raw string
-     * @param timeFormat example : "yyyy-MM-dd HH:mm:ss"
-     * @return replaced string
-     */
     public static String substitute(String str, String timeFormat) {
-
-        final SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
-        final String formattedDate = sdf.format(new Date());
-
-        final Map<String, String> valuesMap = new HashMap<>(3);
-        valuesMap.put("uuid", UUID.randomUUID().toString());
-        valuesMap.put("now", formattedDate);
-        valuesMap.put(timeFormat, formattedDate);
-        final StrSubstitutor sub = new StrSubstitutor(valuesMap);
-        return sub.replace(str);
+        return VariablesSubstitute.substitute(str, timeFormat);

Review comment:
       It's better to use DateTimeFormatter, we can't guarantee what kind of scenarios this will be used in later, but DateTimeFormatter is a better choice than SimpleDateFormat.
   btw,All public methods should have corresponding java doc added




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org