/** * Sets the variable default value delimiter to use. * <p> * The variable default value delimiter is the character or characters that delimit the * variable name and the variable default value. This method allows a string * variable default value delimiter to be easily set. * <p> * If the <code>valueDelimiter</code> is null or empty string, then the variable default * value resolution becomes disabled. * * @param valueDelimiter the variable default value delimiter string to use, may be null or empty * @return this, to enable chaining * @since 3.2 */ public StrSubstitutor setValueDelimiter(final String valueDelimiter) { if (StringUtils.isEmpty(valueDelimiter)) { setValueDelimiterMatcher(null); return this; } return setValueDelimiterMatcher(StrMatcher.stringMatcher(valueDelimiter)); }
/** * Sets the variable default value delimiter to use. * <p> * The variable default value delimiter is the character or characters that delimit the * variable name and the variable default value. This method allows a single character * variable default value delimiter to be easily set. * * @param valueDelimiter the variable default value delimiter character to use * @return this, to enable chaining * @since 3.2 */ public StrSubstitutor setValueDelimiter(final char valueDelimiter) { return setValueDelimiterMatcher(StrMatcher.charMatcher(valueDelimiter)); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiterMatcher(DEFAULT_VALUE_DELIMITER); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefixMatcher the prefix for variables, not null * @param suffixMatcher the suffix for variables, not null * @param escape the escape character * @param valueDelimiterMatcher the variable default value delimiter matcher, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor( final StrLookup<?> variableResolver, final StrMatcher prefixMatcher, final StrMatcher suffixMatcher, final char escape, final StrMatcher valueDelimiterMatcher) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); this.setValueDelimiterMatcher(valueDelimiterMatcher); }
@Test public void testDefaultValueDelimiters() { final Map<String, String> map = new HashMap<>(); map.put("animal", "fox"); map.put("target", "dog"); StrSubstitutor sub = new StrSubstitutor(map, "${", "}", '$'); assertEquals("The fox jumps over the lazy dog. 1234567890.", sub.replace("The ${animal} jumps over the lazy ${target}. ${undefined.number:-1234567890}.")); sub = new StrSubstitutor(map, "${", "}", '$', "?:"); assertEquals("The fox jumps over the lazy dog. 1234567890.", sub.replace("The ${animal} jumps over the lazy ${target}. ${undefined.number?:1234567890}.")); sub = new StrSubstitutor(map, "${", "}", '$', "||"); assertEquals("The fox jumps over the lazy dog. 1234567890.", sub.replace("The ${animal} jumps over the lazy ${target}. ${undefined.number||1234567890}.")); sub = new StrSubstitutor(map, "${", "}", '$', "!"); assertEquals("The fox jumps over the lazy dog. 1234567890.", sub.replace("The ${animal} jumps over the lazy ${target}. ${undefined.number!1234567890}.")); sub = new StrSubstitutor(map, "${", "}", '$', ""); sub.setValueDelimiterMatcher(null); assertEquals("The fox jumps over the lazy dog. ${undefined.number!1234567890}.", sub.replace("The ${animal} jumps over the lazy ${target}. ${undefined.number!1234567890}.")); sub = new StrSubstitutor(map, "${", "}", '$'); sub.setValueDelimiterMatcher(null); assertEquals("The fox jumps over the lazy dog. ${undefined.number!1234567890}.", sub.replace("The ${animal} jumps over the lazy ${target}. ${undefined.number!1234567890}.")); }
/** * Tests get set. */ @Test public void testGetSetValueDelimiter() { final StrSubstitutor sub = new StrSubstitutor(); assertTrue(sub.getValueDelimiterMatcher() instanceof StrMatcher.StringMatcher); sub.setValueDelimiter(':'); assertTrue(sub.getValueDelimiterMatcher() instanceof StrMatcher.CharMatcher); sub.setValueDelimiter("||"); assertTrue(sub.getValueDelimiterMatcher() instanceof StrMatcher.StringMatcher); sub.setValueDelimiter(null); assertNull(sub.getValueDelimiterMatcher()); final StrMatcher matcher = StrMatcher.commaMatcher(); sub.setValueDelimiterMatcher(matcher); assertSame(matcher, sub.getValueDelimiterMatcher()); sub.setValueDelimiterMatcher(null); assertNull(sub.getValueDelimiterMatcher()); }
/** * Sets the variable default value delimiter to use. * <p> * The variable default value delimiter is the character or characters that delimit the * variable name and the variable default value. This method allows a string * variable default value delimiter to be easily set. * <p> * If the <code>valueDelimiter</code> is null or empty string, then the variable default * value resolution becomes disabled. * * @param valueDelimiter the variable default value delimiter string to use, may be null or empty * @return this, to enable chaining * @since 3.2 */ public StrSubstitutor setValueDelimiter(final String valueDelimiter) { if (StringUtils.isEmpty(valueDelimiter)) { setValueDelimiterMatcher(null); return this; } return setValueDelimiterMatcher(StrMatcher.stringMatcher(valueDelimiter)); }
/** * Sets the variable default value delimiter to use. * <p> * The variable default value delimiter is the character or characters that delimit the * variable name and the variable default value. This method allows a string * variable default value delimiter to be easily set. * <p> * If the <code>valueDelimiter</code> is null or empty string, then the variable default * value resolution becomes disabled. * * @param valueDelimiter the variable default value delimiter string to use, may be null or empty * @return this, to enable chaining * @since 3.2 */ public StrSubstitutor setValueDelimiter(final String valueDelimiter) { if (StringUtils.isEmpty(valueDelimiter)) { setValueDelimiterMatcher(null); return this; } return setValueDelimiterMatcher(StrMatcher.stringMatcher(valueDelimiter)); }
/** * Sets the variable default value delimiter to use. * <p> * The variable default value delimiter is the character or characters that delimit the * variable name and the variable default value. This method allows a string * variable default value delimiter to be easily set. * <p> * If the <code>valueDelimiter</code> is null or empty string, then the variable default * value resolution becomes disabled. * * @param valueDelimiter the variable default value delimiter string to use, may be null or empty * @return this, to enable chaining * @since 3.2 */ public StrSubstitutor setValueDelimiter(final String valueDelimiter) { if (StringUtils.isEmpty(valueDelimiter)) { setValueDelimiterMatcher(null); return this; } return setValueDelimiterMatcher(StrMatcher.stringMatcher(valueDelimiter)); }
/** * Sets the variable default value delimiter to use. * <p> * The variable default value delimiter is the character or characters that delimit the * variable name and the variable default value. This method allows a single character * variable default value delimiter to be easily set. * * @param valueDelimiter the variable default value delimiter character to use * @return this, to enable chaining * @since 3.2 */ public StrSubstitutor setValueDelimiter(final char valueDelimiter) { return setValueDelimiterMatcher(StrMatcher.charMatcher(valueDelimiter)); }
/** * Sets the variable default value delimiter to use. * <p> * The variable default value delimiter is the character or characters that delimit the * variable name and the variable default value. This method allows a single character * variable default value delimiter to be easily set. * * @param valueDelimiter the variable default value delimiter character to use * @return this, to enable chaining * @since 3.2 */ public StrSubstitutor setValueDelimiter(final char valueDelimiter) { return setValueDelimiterMatcher(StrMatcher.charMatcher(valueDelimiter)); }
/** * Sets the variable default value delimiter to use. * <p> * The variable default value delimiter is the character or characters that delimit the * variable name and the variable default value. This method allows a single character * variable default value delimiter to be easily set. * * @param valueDelimiter the variable default value delimiter character to use * @return this, to enable chaining * @since 3.2 */ public StrSubstitutor setValueDelimiter(final char valueDelimiter) { return setValueDelimiterMatcher(StrMatcher.charMatcher(valueDelimiter)); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiterMatcher(DEFAULT_VALUE_DELIMITER); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiterMatcher(DEFAULT_VALUE_DELIMITER); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiterMatcher(DEFAULT_VALUE_DELIMITER); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefixMatcher the prefix for variables, not null * @param suffixMatcher the suffix for variables, not null * @param escape the escape character * @param valueDelimiterMatcher the variable default value delimiter matcher, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor( final StrLookup<?> variableResolver, final StrMatcher prefixMatcher, final StrMatcher suffixMatcher, final char escape, final StrMatcher valueDelimiterMatcher) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); this.setValueDelimiterMatcher(valueDelimiterMatcher); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefixMatcher the prefix for variables, not null * @param suffixMatcher the suffix for variables, not null * @param escape the escape character * @param valueDelimiterMatcher the variable default value delimiter matcher, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor( final StrLookup<?> variableResolver, final StrMatcher prefixMatcher, final StrMatcher suffixMatcher, final char escape, final StrMatcher valueDelimiterMatcher) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); this.setValueDelimiterMatcher(valueDelimiterMatcher); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefixMatcher the prefix for variables, not null * @param suffixMatcher the suffix for variables, not null * @param escape the escape character * @param valueDelimiterMatcher the variable default value delimiter matcher, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor( final StrLookup<?> variableResolver, final StrMatcher prefixMatcher, final StrMatcher suffixMatcher, final char escape, final StrMatcher valueDelimiterMatcher) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); this.setValueDelimiterMatcher(valueDelimiterMatcher); }