Java Code Examples for org.springframework.util.StringUtils.collectionToCommaDelimitedString()

The following are Jave code examples for showing how to use collectionToCommaDelimitedString() of the org.springframework.util.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: spring-security-oauth2-boot   File: FixedAuthoritiesExtractor.java   View Source Code Vote up 6 votes
private String asAuthorities(Object object) {
	List<Object> authorities = new ArrayList<>();
	if (object instanceof Collection) {
		Collection<?> collection = (Collection<?>) object;
		object = collection.toArray(new Object[0]);
	}
	if (ObjectUtils.isArray(object)) {
		Object[] array = (Object[]) object;
		for (Object value : array) {
			if (value instanceof String) {
				authorities.add(value);
			}
			else if (value instanceof Map) {
				authorities.add(asAuthority((Map<?, ?>) value));
			}
			else {
				authorities.add(value);
			}
		}
		return StringUtils.collectionToCommaDelimitedString(authorities);
	}
	return object.toString();
}
 
Example 2
Project: alfresco-repository   File: ExtendedPropertyFieldProcessor.java   View Source Code Vote up 6 votes
@Override
public Object getValue(QName name, ContentModelItemData<?> data)
{
    Serializable value = data.getPropertyValue(name);
    if (value != null && value instanceof List<?>)
    {
        List<?> list = (List<?>) value;
        if(!list.isEmpty() && list.get(0) instanceof String) 
        {
            List<String> escapedValues = new ArrayList<String>(list.size());
            for(Object listValue : list)
            {
               escapedValues.add(escape((String)listValue));
            }
            return StringUtils.collectionToCommaDelimitedString(escapedValues);
        }
    }
    return super.getValue(name, data);
}
 
Example 3
Project: lams   File: StaticListableBeanFactory.java   View Source Code Vote up 6 votes
@Override
public Class<?> getType(String name) throws NoSuchBeanDefinitionException {
	String beanName = BeanFactoryUtils.transformedBeanName(name);

	Object bean = this.beans.get(beanName);
	if (bean == null) {
		throw new NoSuchBeanDefinitionException(beanName,
				"Defined beans are [" + StringUtils.collectionToCommaDelimitedString(this.beans.keySet()) + "]");
	}

	if (bean instanceof FactoryBean && !BeanFactoryUtils.isFactoryDereference(name)) {
		// If it's a FactoryBean, we want to look at what it creates, not the factory class.
		return ((FactoryBean<?>) bean).getObjectType();
	}
	return bean.getClass();
}
 
Example 4
Project: lams   File: HttpHeaders.java   View Source Code Vote up 6 votes
/**
 * Return the list of acceptable {@linkplain MediaType media types}, as specified by the {@code Accept} header.
 * <p>Returns an empty list when the acceptable media types are unspecified.
 * @return the acceptable media types
 */
public List<MediaType> getAccept() {
	String value = getFirst(ACCEPT);
	List<MediaType> result = (value != null ? MediaType.parseMediaTypes(value) : Collections.<MediaType>emptyList());

	// Some containers parse 'Accept' into multiple values
	if (result.size() == 1) {
		List<String> acceptHeader = get(ACCEPT);
		if (acceptHeader.size() > 1) {
			value = StringUtils.collectionToCommaDelimitedString(acceptHeader);
			result = MediaType.parseMediaTypes(value);
		}
	}

	return result;
}
 
Example 5
Project: spring-cloud-skipper   File: AppDeployerDataRepositoryImpl.java   View Source Code Vote up 5 votes
@Override
public AppDeployerData findByReleaseNameAndReleaseVersionRequired(String releaseName, Integer releaseVersion) {
	AppDeployerData appDeployerData = appDeployerDataRepository.findByReleaseNameAndReleaseVersion(releaseName,
			releaseVersion);
	if (appDeployerData == null) {
		List<AppDeployerData> appDeployerDataList = StreamSupport
				.stream(appDeployerDataRepository.findAll().spliterator(), false)
				.collect(Collectors.toList());
		String existingDeployerData = StringUtils.collectionToCommaDelimitedString(appDeployerDataList);
		throw new SkipperException(String.format("No AppDeployerData found for release '%s' version '%s'." +
				"AppDeployerData = %s",
				releaseName, releaseVersion, existingDeployerData));
	}
	return appDeployerData;
}
 
Example 6
Project: lams   File: StaticListableBeanFactory.java   View Source Code Vote up 5 votes
@Override
public Object getBean(String name) throws BeansException {
	String beanName = BeanFactoryUtils.transformedBeanName(name);
	Object bean = this.beans.get(beanName);

	if (bean == null) {
		throw new NoSuchBeanDefinitionException(beanName,
				"Defined beans are [" + StringUtils.collectionToCommaDelimitedString(this.beans.keySet()) + "]");
	}

	// Don't let calling code try to dereference the
	// bean factory if the bean isn't a factory
	if (BeanFactoryUtils.isFactoryDereference(name) && !(bean instanceof FactoryBean)) {
		throw new BeanIsNotAFactoryException(beanName, bean.getClass());
	}

	if (bean instanceof FactoryBean && !BeanFactoryUtils.isFactoryDereference(name)) {
		try {
			return ((FactoryBean<?>) bean).getObject();
		}
		catch (Exception ex) {
			throw new BeanCreationException(beanName, "FactoryBean threw exception on object creation", ex);
		}
	}
	else {
		return bean;
	}
}
 
Example 7
Project: spring-data-ebean   File: Converters.java   View Source Code Vote up 5 votes
/**
 * Convert spring data Sort to Ebean OrderBy.
 *
 * @param sort
 * @param <T>
 * @return
 */
public static <T> OrderBy<T> convertToEbeanOrderBy(Sort sort) {
  if (sort == null) {
    return null;
  }
  List<String> list = new ArrayList<>();
  while (sort.iterator().hasNext()) {
    Sort.Order so = sort.iterator().next();
    list.add(so.getDirection() == Sort.Direction.ASC ? so.getProperty() + " asc" : so.getProperty() + " desc");
  }
  return new OrderBy<T>(StringUtils.collectionToCommaDelimitedString(list));
}
 
Example 8
Project: KPBlog   File: BlogUserDetails.java   View Source Code Vote up 4 votes
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
    String userRoles = StringUtils.collectionToCommaDelimitedString(this.roles);
    return AuthorityUtils.commaSeparatedStringToAuthorityList(userRoles);
}
 
Example 9
Project: chimera   File: Q2DeploymentsHealthIndicator.java   View Source Code Vote up 4 votes
@Override
protected void doHealthCheck(Builder builder) throws Exception
{
    final MBeanServer server = getMBeanServer();

    if (server != null)
    {
        final ObjectName on = new ObjectName("Q2:type=qbean,service=*");
        final Set<ObjectName> names = server.queryNames(on, null);
        final Stream<ObjectName> s = names.stream();

        final long muxInTransitCount = getMuxInTransitCount(server, names);
        final long tmInTransitCount = getTmInTransitCount(server, names);

        builder.withDetail("mux.in-transit", String.valueOf(muxInTransitCount));
        builder.withDetail("tm.in-transit", String.valueOf(tmInTransitCount));
        builder.withDetail("in-transit", String.valueOf(Math.max(muxInTransitCount, tmInTransitCount)));

        if (s.allMatch(name -> getStatus(server, name) == QBean.STARTED))
        {
            builder.up();
        }
        else if (s.anyMatch(name -> getStatus(server, name) == QBean.FAILED))
        {
            long cnt = s.filter(name -> getStatus(server, name) == QBean.FAILED).count();

            Set<String> objs = s.filter(name -> getStatus(server, name) == QBean.FAILED)
                .map(ObjectName::getCanonicalName)
                .collect(Collectors.toSet());

            String failedServices = StringUtils.collectionToCommaDelimitedString(objs);
            builder.withDetail("failed-count", String.valueOf(cnt));
            builder.withDetail("failed-services", failedServices);
            builder.status("failed");
        }
        else if (s.allMatch(name -> getStatus(server, name) == QBean.DESTROYED))
        {
            builder.outOfService();
        }
        else if (s.allMatch(name -> getStatus(server, name) == QBean.STOPPED))
        {
            builder.down();
        }
        else
        {
            builder.unknown();
        }
    }
    else
    {
        builder.unknown();
    }
}
 
Example 10
Project: alfresco-repository   File: PropertyFieldProcessor.java   View Source Code Vote up 4 votes
@Override
public Object getValue(QName name, ContentModelItemData<?> data)
{
    Serializable value = data.getPropertyValue(name);
    if (value == null)
    {
        return getDefaultValue(name, data);
    }
    
    if (value instanceof Collection<?>)
    {
        // temporarily add repeating field data as a comma
        // separated list, this will be changed to using
        // a separate field for each value once we have full
        // UI support in place.
        Collection<?> values = (Collection<?>) value;
        
        // if the non empty collection is a List of Date objects 
        // we need to convert each date to a ISO8601 format 
        if (value instanceof List<?> && !values.isEmpty())
        {
            List<?> list = (List<?>)values;
            if (list.get(0) instanceof Date)
            {
                List<String> isoDates = new ArrayList<String>(list.size());
                for (Object date : list)
                {
                    isoDates.add(ISO8601DateFormat.format((Date)date));
                }
                
                // return the ISO formatted dates as a comma delimited string 
                return StringUtils.collectionToCommaDelimitedString(isoDates);
            }
        }
        
        // return everything else using toString()
        return StringUtils.collectionToCommaDelimitedString(values);
    }
    else if (value instanceof ContentData)
    {
        // for content properties retrieve the info URL rather than the
        // the object value itself
        ContentData contentData = (ContentData)value;
        return contentData.getInfoUrl();
    }
    else if (value instanceof NodeRef)
    {
        return ((NodeRef)value).toString();
    }
    
    return value;
}
 
Example 11
Project: spring-oauth2-jwt   File: CustomUserDetails.java   View Source Code Vote up 4 votes
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
    String roles = StringUtils.collectionToCommaDelimitedString(userRoles);
    return AuthorityUtils.commaSeparatedStringToAuthorityList(roles);
}
 
Example 12
Project: SoftUni   File: ListUserDetails.java   View Source Code Vote up 4 votes
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
    String userRoles = StringUtils.collectionToCommaDelimitedString(this.roles);
    return AuthorityUtils.commaSeparatedStringToAuthorityList(userRoles);
}
 
Example 13
Project: Spring-web-shop-project   File: CustomUserDetails.java   View Source Code Vote up 4 votes
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {

    String roles = StringUtils.collectionToCommaDelimitedString(userRoles);
    return AuthorityUtils.commaSeparatedStringToAuthorityList(roles);
}
 
Example 14
Project: lams   File: NoUniqueBeanDefinitionException.java   View Source Code Vote up 2 votes
/**
 * Create a new {@code NoUniqueBeanDefinitionException}.
 * @param type required type of the non-unique bean
 * @param beanNamesFound the names of all matching beans (as a Collection)
 */
public NoUniqueBeanDefinitionException(Class<?> type, Collection<String> beanNamesFound) {
	this(type, beanNamesFound.size(), "expected single matching bean but found " + beanNamesFound.size() + ": " +
			StringUtils.collectionToCommaDelimitedString(beanNamesFound));
}
 
Example 15
Project: Lagerta   File: CommandServiceCLIAware.java   View Source Code Vote up 2 votes
/**
 * Formats snapshot to cozy string.
 * @param metadata to get string for.
 * @return string representation.
 */
private String stringify(Metadata metadata) {
    return "Snapshot(timestamp=" + metadata.getTimestamp() + ", labels=" +
        StringUtils.collectionToCommaDelimitedString(commandService.metadataTree().getLabels(metadata)) + ")";
}