/** * Set a single notification type, or a list of notification types * as comma-delimited String. */ public void setNotificationType(String notificationType) { this.notificationTypes = StringUtils.commaDelimitedListToStringArray(notificationType); }
/** * Convert a comma delimited list (e.g., a row from a CSV file) into a set. * <p>Note that this will suppress duplicates, and as of 4.2, the elements in * the returned set will preserve the original order in a {@link LinkedHashSet}. * @param str the input {@code String} (potentially {@code null} or empty) * @return a set of {@code String} entries in the list * @see #removeDuplicateStrings(String[]) */ public static Set<String> commaDelimitedListToSet(@Nullable String str) { String[] tokens = commaDelimitedListToStringArray(str); return new LinkedHashSet<>(Arrays.asList(tokens)); }
/** * See {@link ScriptTemplateConfigurer#setResourceLoaderPath(String)} documentation. */ public void setResourceLoaderPath(String resourceLoaderPath) { String[] paths = StringUtils.commaDelimitedListToStringArray(resourceLoaderPath); this.resourceLoaderPaths = new String[paths.length + 1]; this.resourceLoaderPaths[0] = ""; for (int i = 0; i < paths.length; i++) { String path = paths[i]; if (!path.endsWith("/") && !path.endsWith(":")) { path = path + "/"; } this.resourceLoaderPaths[i + 1] = path; } }
Props(Element root) { String defaultCache = root.getAttribute("cache"); this.key = root.getAttribute("key"); this.keyGenerator = root.getAttribute("key-generator"); this.cacheManager = root.getAttribute("cache-manager"); this.condition = root.getAttribute("condition"); this.method = root.getAttribute(METHOD_ATTRIBUTE); if (StringUtils.hasText(defaultCache)) { this.caches = StringUtils.commaDelimitedListToStringArray(defaultCache.trim()); } }
/** * Set by creator of this advice object if the argument names are known. * <p>This could be for example because they have been explicitly specified in XML, * or in an advice annotation. * @param argNames comma delimited list of arg names */ public void setArgumentNames(String argNames) { String[] tokens = StringUtils.commaDelimitedListToStringArray(argNames); setArgumentNamesFromStringArray(tokens); }
/** * Return any patterns provided in the 'default-autowire-candidates' * attribute of the top-level {@code <beans/>} element. */ @Nullable public String[] getAutowireCandidatePatterns() { String candidatePattern = this.defaults.getAutowireCandidates(); return (candidatePattern != null ? StringUtils.commaDelimitedListToStringArray(candidatePattern) : null); }
/** * Set the mappings of bean keys to a comma-separated list of method names. * The property key should match the bean key and the property value should match * the list of method names. When searching for method names for a bean, Spring * will check these mappings first. * @param mappings the mappings of bean keys to method names */ public void setMethodMappings(Properties mappings) { this.methodMappings = new HashMap<>(); for (Enumeration<?> en = mappings.keys(); en.hasMoreElements();) { String beanKey = (String) en.nextElement(); String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey)); this.methodMappings.put(beanKey, new HashSet<>(Arrays.asList(methodNames))); } }
/** * Get the accept-version header. * @since 5.0.7 */ @Nullable public String[] getAcceptVersion() { String value = getFirst(ACCEPT_VERSION); return value != null ? StringUtils.commaDelimitedListToStringArray(value) : null; }
/** * Replace the values in the comma-separated list (case insensitive) * with their index in the list. * @return a new String with the values from the list replaced */ private String replaceOrdinals(String value, String commaSeparatedList) { String[] list = StringUtils.commaDelimitedListToStringArray(commaSeparatedList); for (int i = 0; i < list.length; i++) { String item = list[i].toUpperCase(); value = StringUtils.replace(value.toUpperCase(), item, "" + i); } return value; }
@Nullable private String selectProtocol(HttpHeaders headers, WebSocketHandler handler) { String protocolHeader = headers.getFirst(SEC_WEBSOCKET_PROTOCOL); if (protocolHeader != null) { List<String> supportedProtocols = handler.getSubProtocols(); for (String protocol : StringUtils.commaDelimitedListToStringArray(protocolHeader)) { if (supportedProtocols.contains(protocol)) { return protocol; } } } return null; }
private void addNoRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String noRollbackForValue) { String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(noRollbackForValue); for (String typeName : exceptionTypeNames) { rollbackRules.add(new NoRollbackRuleAttribute(StringUtils.trimWhitespace(typeName))); } }
private void addRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String rollbackForValue) { String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(rollbackForValue); for (String typeName : exceptionTypeNames) { rollbackRules.add(new RollbackRuleAttribute(StringUtils.trimWhitespace(typeName))); } }
@Override public void setAsText(String text) throws IllegalArgumentException { if (StringUtils.hasText(text)) { String[] classNames = StringUtils.commaDelimitedListToStringArray(text); Class<?>[] classes = new Class<?>[classNames.length]; for (int i = 0; i < classNames.length; i++) { String className = classNames[i].trim(); classes[i] = ClassUtils.resolveClassName(className, this.classLoader); } setValue(classes); } else { setValue(null); } }
@Override public Integer[] convert(String source) { String[] srcArray = StringUtils.commaDelimitedListToStringArray(source); return Arrays.stream(srcArray).map(s -> s.substring(1)).map(Integer::valueOf).toArray(Integer[]::new); } }
private void doTestStringArrayReverseTransformationMatches(String[] sa) { String[] reverse = StringUtils.commaDelimitedListToStringArray(StringUtils.arrayToCommaDelimitedString(sa)); assertEquals("Reverse transformation is equal", Arrays.asList(sa), Arrays.asList(reverse)); }
private void doTestCommaDelimitedListToStringArrayLegalMatch(String[] components) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < components.length; i++) { if (i != 0) { sb.append(","); } sb.append(components[i]); } String[] sa = StringUtils.commaDelimitedListToStringArray(sb.toString()); assertTrue("String array isn't null with legal match", sa != null); assertEquals("String array length is correct with legal match", components.length, sa.length); assertTrue("Output equals input", Arrays.equals(sa, components)); }
@Test public void testCommaDelimitedListToStringArraySingleString() { // Could read these from files String s = "woeirqupoiewuropqiewuorpqiwueopriquwopeiurqopwieur"; String[] sa = StringUtils.commaDelimitedListToStringArray(s); assertTrue("Found one String with no delimiters", sa.length == 1); assertTrue("Single array entry matches input String with no delimiters", sa[0].equals(s)); }
/** * We expect to see the empty Strings in the output. */ @Test public void testCommaDelimitedListToStringArrayEmptyStrings() { // Could read these from files String[] sa = StringUtils.commaDelimitedListToStringArray("a,,b"); assertEquals("a,,b produces array length 3", 3, sa.length); assertTrue("components are correct", sa[0].equals("a") && sa[1].equals("") && sa[2].equals("b")); sa = new String[] {"", "", "a", ""}; doTestCommaDelimitedListToStringArrayLegalMatch(sa); }
@Test public void testCommaDelimitedListToStringArrayWithEmptyStringProducesEmptyArray() { String[] sa = StringUtils.commaDelimitedListToStringArray(""); assertTrue("String array isn't null with null input", sa != null); assertTrue("String array length == 0 with null input", sa.length == 0); }
@Test public void testCommaDelimitedListToStringArrayWithNullProducesEmptyArray() { String[] sa = StringUtils.commaDelimitedListToStringArray(null); assertTrue("String array isn't null with null input", sa != null); assertTrue("String array length == 0 with null input", sa.length == 0); }