List of usage examples for org.springframework.util StringUtils arrayToDelimitedString
public static String arrayToDelimitedString(@Nullable Object[] arr, String delim)
From source file:org.opennms.netmgt.dao.support.PropertiesGraphDao.java
/** {@inheritDoc} */ @Override/*from www . j a v a 2s. c om*/ public PrefabGraph[] getPrefabGraphsForResource(final OnmsResource resource) { if (resource == null) { LOG.warn("returning empty graph list for resource because it is null"); return new PrefabGraph[0]; } Set<OnmsAttribute> attributes = new LinkedHashSet<>(resource.getAttributes()); // Check if there are no attributes if (attributes.size() == 0) { LOG.debug("returning empty graph list for resource {} because its attribute list is empty", resource); return new PrefabGraph[0]; } Set<String> availableRrdAttributes = new LinkedHashSet<>(resource.getRrdGraphAttributes().keySet()); Set<String> availableStringAttributes = new LinkedHashSet<>( resource.getStringPropertyAttributes().keySet()); Set<String> availableExternalAttributes = new LinkedHashSet<>( resource.getExternalValueAttributes().keySet()); // Check if there are no RRD attributes if (availableRrdAttributes.size() == 0) { LOG.debug("returning empty graph list for resource {} because it has no RRD attributes", resource); return new PrefabGraph[0]; } String resourceType = resource.getResourceType().getName(); Map<String, PrefabGraph> returnList = new LinkedHashMap<String, PrefabGraph>(); for (PrefabGraph query : getAllPrefabGraphs()) { if (resourceType != null && !query.hasMatchingType(resourceType)) { LOG.debug("skipping {} because its types \"{}\" does not match resourceType \"{}\"", query.getName(), StringUtils.arrayToDelimitedString(query.getTypes(), ", "), resourceType); continue; } if (!verifyAttributesExist(query, "RRD", Arrays.asList(query.getColumns()), availableRrdAttributes)) { continue; } if (!verifyAttributesExist(query, "string property", Arrays.asList(query.getPropertiesValues()), availableStringAttributes)) { continue; } if (!verifyAttributesExist(query, "external value", Arrays.asList(query.getExternalValues()), availableExternalAttributes)) { continue; } LOG.debug("adding {} to query list", query.getName()); returnList.put(query.getName(), query); } if (LOG.isDebugEnabled()) { ArrayList<String> nameList = new ArrayList<String>(returnList.size()); for (PrefabGraph graph : returnList.values()) { nameList.add(graph.getName()); } LOG.debug("found {} prefabricated graphs for resource {}: {}", nameList.size(), resource, StringUtils.collectionToDelimitedString(nameList, ", ")); } final Set<String> suppressReports = new HashSet<String>(); for (final Entry<String, PrefabGraph> entry : returnList.entrySet()) { suppressReports.addAll(Arrays.asList(entry.getValue().getSuppress())); } suppressReports.retainAll(returnList.keySet()); if (suppressReports.size() > 0) { LOG.debug("suppressing {} prefabricated graphs for resource {}: {}", suppressReports.size(), resource, StringUtils.collectionToDelimitedString(suppressReports, ", ")); } for (final String suppressReport : suppressReports) { returnList.remove(suppressReport); } return returnList.values().toArray(new PrefabGraph[returnList.size()]); }
From source file:org.springframework.beans.AbstractPropertyAccessorTests.java
@Test public void setStringPropertyWithCustomEditor() throws Exception { TestBean target = new TestBean(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.registerCustomEditor(String.class, "name", new PropertyEditorSupport() { @Override//from ww w .j a v a 2 s .c o m public void setValue(Object value) { if (value instanceof String[]) { setValue(StringUtils.arrayToDelimitedString(((String[]) value), "-")); } else { super.setValue(value != null ? value : ""); } } }); accessor.setPropertyValue("name", new String[] {}); assertEquals("", target.getName()); accessor.setPropertyValue("name", new String[] { "a1", "b2" }); assertEquals("a1-b2", target.getName()); accessor.setPropertyValue("name", null); assertEquals("", target.getName()); }
From source file:org.springframework.beans.BeanWrapperTests.java
@Test public void testStringPropertyWithCustomEditor() throws Exception { TestBean tb = new TestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(String.class, "name", new PropertyEditorSupport() { @Override//w ww. j a v a 2 s . c o m public void setValue(Object value) { if (value instanceof String[]) { setValue(StringUtils.arrayToDelimitedString(((String[]) value), "-")); } else { super.setValue(value != null ? value : ""); } } }); bw.setPropertyValue("name", new String[] {}); assertEquals("", tb.getName()); bw.setPropertyValue("name", new String[] { "a1", "b2" }); assertEquals("a1-b2", tb.getName()); bw.setPropertyValue("name", null); assertEquals("", tb.getName()); }
From source file:org.springframework.cloud.bus.DefaultBusPathMatcher.java
protected boolean matchMultiProfile(String pattern, String applicationContextID) { log.debug("matchMultiProfile : " + pattern + ", " + applicationContextID); // parse the application-context-id String[] appContextIDTokens = tokenizeToStringArray(applicationContextID, ":"); if (appContextIDTokens.length <= 1) { // no parts, default to delegate which already returned false; return false; }// ww w. ja v a 2s. c om String selfProfiles = appContextIDTokens[1]; // short circuit if possible String[] profiles = tokenizeToStringArray(selfProfiles, ","); if (profiles.length == 1) { // there aren't multiple profiles to check, the delegate match was // originally false so return what delegate determined return false; } // gather candidate ids with a single profile rather than a comma separated list String[] idsWithSingleProfile = new String[profiles.length]; for (int i = 0; i < profiles.length; i++) { //replace comma separated profiles with single profile String profile = profiles[i]; String[] newTokens = new String[appContextIDTokens.length]; System.arraycopy(appContextIDTokens, 0, newTokens, 0, appContextIDTokens.length); newTokens[1] = profile; idsWithSingleProfile[i] = StringUtils.arrayToDelimitedString(newTokens, ":"); } for (String id : idsWithSingleProfile) { if (delagateMatcher.match(pattern, id)) { log.debug("matched true"); return true; } } log.debug("matched false"); return false; }
From source file:org.springframework.data.gemfire.config.AbstractRegionParser.java
private String buildSubRegionPath(String parentName, String regionName) { String regionPath = StringUtils.arrayToDelimitedString(new String[] { parentName, regionName }, "/"); if (!regionPath.startsWith("/")) { regionPath = "/" + regionPath; }/*from w ww. ja v a 2s . c o m*/ return regionPath; }
From source file:org.springframework.data.gemfire.config.xml.AbstractRegionParser.java
private String buildSubRegionPath(String parentName, String regionName) { String regionPath = StringUtils.arrayToDelimitedString(new String[] { parentName, regionName }, "/"); if (!regionPath.startsWith("/")) { regionPath = "/" + regionPath; }//from w w w. j ava2 s. co m return regionPath; }
From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryBootDashModelMockingTest.java
private void assertSorted(ImmutableList<IAction> actions) { String[] actionNames = new String[actions.size()]; for (int i = 0; i < actionNames.length; i++) { actionNames[i] = actions.get(i).getText(); }/*from w ww . j av a 2s . c o m*/ String actual = StringUtils.arrayToDelimitedString(actionNames, "\n"); Arrays.sort(actionNames); String expected = StringUtils.arrayToDelimitedString(actionNames, "\n"); assertEquals(expected, actual); }
From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java
/** * Set multiple JAXB context paths. The given array of context paths gets * converted to a colon-delimited string, as supported by JAXB. *//*w w w . j a va2 s.c o m*/ public void setContextPaths(String... contextPaths) { Assert.notEmpty(contextPaths, "'contextPaths' must not be empty"); this.contextPath = StringUtils.arrayToDelimitedString(contextPaths, ":"); }
From source file:org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.java
/** * Handle the case where no request handler method was found for the particular HTTP request method. * <p>The default implementation logs a warning, sends an HTTP 405 error, sets the "Allow" header, * and returns an empty {@code ModelAndView}. Alternatively, a fallback view could be chosen, * or the HttpRequestMethodNotSupportedException could be rethrown as-is. * @param ex the HttpRequestMethodNotSupportedException to be handled * @param request current HTTP request/*from w w w . j a v a 2 s. c om*/ * @param response current HTTP response * @param handler the executed handler, or {@code null} if none chosen * at the time of the exception (for example, if multipart resolution failed) * @return an empty ModelAndView indicating the exception was handled * @throws IOException potentially thrown from response.sendError() */ protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { pageNotFoundLogger.warn(ex.getMessage()); String[] supportedMethods = ex.getSupportedMethods(); if (supportedMethods != null) { response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", ")); } response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, ex.getMessage()); return new ModelAndView(); }
From source file:org.springframework.web.servlet.support.BindStatus.java
/** * Return an error message string, concatenating all messages * separated by the given delimiter.//from w ww.j a v a 2 s . com * @param delimiter separator string, e.g. ", " or "<br>" * @return the error message string */ public String getErrorMessagesAsString(String delimiter) { return StringUtils.arrayToDelimitedString(this.errorMessages, delimiter); }