FormatUtils { public static String replace(String prop, String replaceWith, String sourceString) { Map<String, String> replacements = new HashMap<String, String>(1); replacements.put(prop, replaceWith); return replaceTokens(sourceString, replacements, true); } private  FormatUtils(); static String replace(String prop, String replaceWith, String sourceString); static String replaceToken(String text, String tokenToReplace, String replaceWithText,
            boolean matchUsingPrefixSuffix); static String replaceTokens(String text, Map<String, String> replacements,
            boolean matchUsingPrefixSuffix); static String formatString(String format, String arg); static boolean toBoolean(String value); static boolean isMixedCase(String text); static boolean isWildCardMatch(String text, String pattern, boolean ignoreCase); static boolean isWildCardMatch(String text, String pattern); static String unescapeWildCards(String str); static String escapeWildCards(String str); static boolean isWildCarded(String str); static String[] wordWrap(String str, int firstLineSize, int nonFirstLineSize); static String[] wordWrap(String str, int lineSize); static String abbreviateForLogging(String value); @SuppressWarnings("rawtypes") static String abbreviateForLogging(List list, int maxCharsToLog); static Date parseDate(String str, String[] parsePatterns); static Date parseDate(String str, String[] parsePatterns, TimeZone timeZone); static Timestamp parseTimestampWithTimezone(String str); static Timestamp parseTimestampWithTimezone(String str, String[] parsePatterns); static String[] splitOnSpacePreserveQuotedStrings(String source); static String replaceCharsToShortenName(String name); static String lower(String str); static String upper(String str); static boolean isInfamousTurkey(); static String stripTurkeyDottedI(String str); static String formatDurationReadable(long duration); static String formatDateTimeISO(Date date); static boolean isInteger(String s); static final String[] TIMESTAMP_PATTERNS; static final String[] TIME_PATTERNS; static final String[] TIMESTAMP_WITH_TIMEZONE_PATTERNS; static final FastDateFormat TIMESTAMP_FORMATTER; static final FastDateFormat TIME_FORMATTER; final static String WILDCARD; final static String WILDCARD_SEPARATOR; final static String NEGATE_TOKEN; final static char WILDCARD_SEPARATOR_CHAR; final static char WILDCARD_CHAR; final static char NEGATE_TOKEN_CHAR; final static String WILDCARD_ESCAPED; final static String WILDCARD_SEPARATOR_ESCAPED; final static String NEGATE_TOKEN_ESCAPED; final static int MAX_CHARS_TO_LOG; }
@Test public void testReplace() { assertEquals(FormatUtils.replace("nodeId", "001", "nodeId = $(nodeId)"), "nodeId = 001"); assertEquals(FormatUtils.replace("nodeId", "001", "nodeId = $(nodeId:0)"), "nodeId = 001"); assertEquals(FormatUtils.replace("nodeId", "001", "nodeId = $(nodeId:0:10)"), "nodeId = 001"); assertEquals(FormatUtils.replace("nodeId", "1234567890ABC", "nodeId = $(nodeId:10)"), "nodeId = ABC"); assertEquals(FormatUtils.replace("nodeId", "1234567890ABC", "nodeId = $(nodeId:10:11)"), "nodeId = A"); assertEquals(FormatUtils.replace("nodeId", "001-002", "nodeId = $(nodeId:4)"), "nodeId = 002"); }