List of usage examples for java.util Collection toString
public String toString()
From source file:com.kelveden.rastajax.cli.Runner.java
private static File findWar() { final Collection<File> wars = FileUtils.listFiles(new File(System.getProperty("user.dir")), new String[] { "war" }, true); LOGGER.info("Found the following wars: " + wars.toString()); if (wars.size() > 0) { return wars.iterator().next(); } else {/*from w w w.j a v a 2s .c o m*/ return null; } }
From source file:it.attocchi.utils.ListUtils.java
/** * //from w ww .j ava 2 s.c o m * @param aListOfString * @return [string, string, ... ] */ public static <T> String toCommaSepared(Collection<T> aListOfString) { String res = ""; if (isNotEmpty(aListOfString)) { res = aListOfString.toString(); } return res; }
From source file:nc.noumea.mairie.organigramme.core.utility.OrganigrammeUtil.java
/** * Mthode pour "charger" une collection, pour viter pb de lazy loading * /* w w w . ja v a 2 s . com*/ * @param collection * collection charger */ public static void chargeCollection(@SuppressWarnings("rawtypes") Collection collection) { // ne pas enlever cette ligne de debug, volontaire if (collection != null) { LOGGER.debug(collection.toString()); } }
From source file:Main.java
/** * Make the log more meanings// w w w . java 2s . c o m * * @param <E> * @param collec * @return */ public static <E> String toLog(String separator, Collection<E> collec) { // using StringBuffer instead of String because expect there are many append operation StringBuffer sb = new StringBuffer(); if (collec == null) { return null; } if (collec.isEmpty()) { return collec.toString(); } sb.append("["); for (Iterator<E> iterator = collec.iterator(); iterator.hasNext();) { E value = iterator.next(); sb.append(separator).append(toString4Log(value)).append(separator); if (iterator.hasNext()) { sb.append(", "); } } sb.append("]"); return sb.toString(); }
From source file:Main.java
/** * Create a textual representation of the given collection, separating the individual elements by the provided separator. * // w w w . j a v a 2 s .c om * @param collection * the collection to represent as text * @param separator * the separator to include between elements of the collection * @return the colleciton's textual representation (or an empty String if the collection is {@code null} or empty) */ public static String toString(final Collection<?> collection, final String separator) { if (collection == null || collection.isEmpty()) { // just return an empty String if the collection is null or empty return ""; } if (separator == null) { // fall back to the collection's toString() method if no custom separator has been specified return collection.toString(); } // guess at a meaningful initial size final StringBuilder builder = new StringBuilder(collection.size() * (16 + separator.length())); boolean addSeparator = false; // iterate over the individual elements for (final Object collectionElement : collection) { if (addSeparator) { builder.append(separator); } else { addSeparator = true; } // null elements are treated as empty Strings if (collectionElement != null) { builder.append(collectionElement.toString()); } } return builder.toString(); }
From source file:org.apache.hadoop.yarn.conf.HAUtil.java
private static void verifyAndSetCurrentRMHAId(Configuration conf) { String rmId = getRMHAId(conf); if (rmId == null) { StringBuilder msg = new StringBuilder(); msg.append("Can not find valid RM_HA_ID. None of "); for (String id : conf.getTrimmedStringCollection(YarnConfiguration.RM_HA_IDS)) { msg.append(addSuffix(YarnConfiguration.RM_ADDRESS, id) + " "); }/*w w w. j a va2s.co m*/ msg.append(" are matching" + " the local address OR " + YarnConfiguration.RM_HA_ID + " is not" + " specified in HA Configuration"); throwBadConfigurationException(msg.toString()); } else { Collection<String> ids = getRMHAIds(conf); if (!ids.contains(rmId)) { throwBadConfigurationException(getRMHAIdNeedToBeIncludedMessage(ids.toString(), rmId)); } } conf.set(YarnConfiguration.RM_HA_ID, rmId); }
From source file:com.evolveum.midpoint.gui.api.component.result.OpResult.java
public static OpResult getOpResult(PageBase page, OperationResult result) { OpResult opResult = new OpResult(); Validate.notNull(result, "Operation result must not be null."); Validate.notNull(result.getStatus(), "Operation result status must not be null."); if (result.getCause() != null && result.getCause() instanceof CommonException) { LocalizableMessage localizableMessage = ((CommonException) result.getCause()).getUserFriendlyMessage(); if (localizableMessage != null) { opResult.message = WebComponentUtil.resolveLocalizableMessage(localizableMessage, page); // Exclamation code: // String key = localizableMessage.getKey() != null ? localizableMessage.getKey() : localizableMessage.getFallbackMessage(); // StringResourceModel stringResourceModel = new StringResourceModel(key, page).setModel(new Model<String>()).setDefaultValue(localizableMessage.getFallbackMessage()) // .setParameters(localizableMessage.getArgs()); // opResult.message = stringResourceModel.getString(); }/*from w w w .j a va2 s . c o m*/ } if (opResult.message == null) { opResult.message = result.getMessage(); } opResult.operation = result.getOperation(); opResult.status = result.getStatus(); opResult.count = result.getCount(); opResult.userFriendlyMessage = result.getUserFriendlyMessage(); if (result.getCause() != null) { Throwable cause = result.getCause(); opResult.exceptionMessage = cause.getMessage(); Writer writer = new StringWriter(); cause.printStackTrace(new PrintWriter(writer)); opResult.exceptionsStackTrace = writer.toString(); } if (result.getParams() != null) { for (Map.Entry<String, Collection<String>> entry : result.getParams().entrySet()) { String paramValue = null; Collection<String> values = entry.getValue(); if (values != null) { paramValue = values.toString(); } opResult.getParams().add(new Param(entry.getKey(), paramValue)); } } if (result.getContext() != null) { for (Map.Entry<String, Collection<String>> entry : result.getContext().entrySet()) { String contextValue = null; Collection<String> values = entry.getValue(); if (values != null) { contextValue = values.toString(); } opResult.getContexts().add(new Context(entry.getKey(), contextValue)); } } if (result.getSubresults() != null) { for (OperationResult subresult : result.getSubresults()) { OpResult subOpResult = OpResult.getOpResult(page, subresult); opResult.getSubresults().add(subOpResult); subOpResult.parent = opResult; if (subOpResult.getBackgroundTaskOid() != null) { opResult.backgroundTaskOid = subOpResult.getBackgroundTaskOid(); } } } if (result.getBackgroundTaskOid() != null) { opResult.backgroundTaskOid = result.getBackgroundTaskOid(); } try { OperationResultType resultType = result.createOperationResultType(); ObjectFactory of = new ObjectFactory(); opResult.xml = page.getPrismContext().xmlSerializer().serialize(of.createOperationResult(resultType)); } catch (SchemaException | RuntimeException ex) { String m = "Can't create xml: " + ex; // error(m); opResult.xml = "<?xml version='1.0'?><message>" + StringEscapeUtils.escapeXml(m) + "</message>"; // throw ex; } return opResult; }
From source file:com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchUtilities.java
/** * Retrieved batch boundary from the given content-type header values. * * @param contentType content-types./*from w ww .j av a 2 s. co m*/ * @return batch boundary. */ public static String getBoundaryFromHeader(final Collection<String> contentType) { final String boundaryKey = ODataBatchConstants.BOUNDARY + "="; if (contentType == null || contentType.isEmpty() || !contentType.toString().contains(boundaryKey)) { throw new IllegalArgumentException("Invalid content type"); } final String headerValue = contentType.toString(); final int start = headerValue.indexOf(boundaryKey) + boundaryKey.length(); int end = headerValue.indexOf(';', start); if (end < 0) { end = headerValue.indexOf(']', start); } final String res = headerValue.substring(start, end); return res.startsWith("--") ? res : "--" + res; }
From source file:org.springframework.security.web.authentication.preauth.websphere.DefaultWASUsernameAndGroupsExtractor.java
/** * Get the WebSphere group names for the given security name. * * @param securityName The security name for which to retrieve the WebSphere group * names//from w w w. jav a 2s . c om * @return the WebSphere group names for the given security name */ @SuppressWarnings("unchecked") private static List<String> getWebSphereGroups(final String securityName) { Context ic = null; try { // TODO: Cache UserRegistry object ic = new InitialContext(); Object objRef = ic.lookup(USER_REGISTRY); Object userReg = invokeMethod(getNarrowMethod(), null, objRef, Class.forName("com.ibm.websphere.security.UserRegistry")); if (logger.isDebugEnabled()) { logger.debug("Determining WebSphere groups for user " + securityName + " using WebSphere UserRegistry " + userReg); } final Collection groups = (Collection) invokeMethod(getGroupsForUserMethod(), userReg, new Object[] { securityName }); if (logger.isDebugEnabled()) { logger.debug("Groups for user " + securityName + ": " + groups.toString()); } return new ArrayList(groups); } catch (Exception e) { logger.error("Exception occured while looking up groups for user", e); throw new RuntimeException("Exception occured while looking up groups for user", e); } finally { try { if (ic != null) { ic.close(); } } catch (NamingException e) { logger.debug("Exception occured while closing context", e); } } }
From source file:com._4dconcept.springframework.data.marklogic.repository.config.MarklogicRepositoryConfigurationExtensionTest.java
private static void assertHasRepo(Class<?> repositoryInterface, Collection<RepositoryConfiguration<RepositoryConfigurationSource>> configs) { for (RepositoryConfiguration<?> config : configs) { if (config.getRepositoryInterface().equals(repositoryInterface.getName())) { return; }//from ww w . ja va2s . co m } fail("Expected to find config for repository interface ".concat(repositoryInterface.getName()) .concat(" but got ").concat(configs.toString())); }