Example usage for org.springframework.util StringUtils collectionToCommaDelimitedString

List of usage examples for org.springframework.util StringUtils collectionToCommaDelimitedString

Introduction

In this page you can find the example usage for org.springframework.util StringUtils collectionToCommaDelimitedString.

Prototype

public static String collectionToCommaDelimitedString(@Nullable Collection<?> coll) 

Source Link

Document

Convert a Collection into a delimited String (e.g., CSV).

Usage

From source file:org.springframework.data.repository.config.AbstractRepositoryConfigDefinitionParser.java

/**
 * Tries to detect a custom implementation for a repository bean by classpath scanning.
 * // w  ww.j  a va  2s .co  m
 * @param config
 * @param parser
 * @return the {@code AbstractBeanDefinition} of the custom implementation or {@literal null} if none found
 */
private AbstractBeanDefinition detectCustomImplementation(T config, ParserContext parser) {

    // Build pattern to lookup implementation class
    Pattern pattern = Pattern.compile(".*\\." + config.getImplementationClassName());

    // Build classpath scanner and lookup bean definition
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
            false);
    provider.setResourceLoader(parser.getReaderContext().getResourceLoader());
    provider.addIncludeFilter(new RegexPatternTypeFilter(pattern));
    Set<BeanDefinition> definitions = provider.findCandidateComponents(config.getBasePackage());

    if (definitions.size() == 0) {
        return null;
    }

    if (definitions.size() == 1) {
        return (AbstractBeanDefinition) definitions.iterator().next();
    }

    List<String> implementationClassNames = new ArrayList<String>();
    for (BeanDefinition bean : definitions) {
        implementationClassNames.add(bean.getBeanClassName());
    }

    throw new IllegalStateException(String.format(
            "Ambiguous custom implementations detected! Found %s but expected a single implementation!",
            StringUtils.collectionToCommaDelimitedString(implementationClassNames)));
}

From source file:org.springframework.data.repository.config.RepositoryBeanDefinitionBuilder.java

/**
 * Tries to detect a custom implementation for a repository bean by classpath scanning.
 * //from   w w w  .  java  2s .c o m
 * @param config
 * @param parser
 * @return the {@code AbstractBeanDefinition} of the custom implementation or {@literal null} if none found
 */
private AbstractBeanDefinition detectCustomImplementation(BeanDefinitionRegistry registry,
        ResourceLoader loader) {

    // Build pattern to lookup implementation class
    Pattern pattern = Pattern.compile(".*\\." + configuration.getImplementationClassName());

    // Build classpath scanner and lookup bean definition
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
            false);
    provider.setResourceLoader(loader);
    provider.addIncludeFilter(new RegexPatternTypeFilter(pattern));

    Set<BeanDefinition> definitions = new HashSet<BeanDefinition>();

    for (String basePackage : configuration.getBasePackages()) {
        definitions.addAll(provider.findCandidateComponents(basePackage));
    }

    if (definitions.isEmpty()) {
        return null;
    }

    if (definitions.size() == 1) {
        return (AbstractBeanDefinition) definitions.iterator().next();
    }

    List<String> implementationClassNames = new ArrayList<String>();
    for (BeanDefinition bean : definitions) {
        implementationClassNames.add(bean.getBeanClassName());
    }

    throw new IllegalStateException(String.format(
            "Ambiguous custom implementations detected! Found %s but expected a single implementation!",
            StringUtils.collectionToCommaDelimitedString(implementationClassNames)));
}

From source file:org.springframework.hateoas.VndErrors.java

@Override
public String toString() {
    return String.format("VndErrors[%s]", StringUtils.collectionToCommaDelimitedString(vndErrors));
}

From source file:org.springframework.integration.history.MessageHistory.java

@Override
public String toString() {
    List<String> names = new ArrayList<String>();
    for (Properties p : this.components) {
        String name = p.getProperty(NAME_PROPERTY);
        if (name != null) {
            names.add(name);/*from  w  w  w .j a  va2s  . c  o  m*/
        }
    }
    return StringUtils.collectionToCommaDelimitedString(names);
}

From source file:org.springframework.integration.x.kafka.KafkaPartitionAllocator.java

@Override
public synchronized Partition[] getObject() throws Exception {
    if (log.isDebugEnabled()) {
        log.debug("Module name is " + moduleName);
        log.debug("Stream name is " + streamName);
        log.debug("Cardinality is " + count);
        log.debug("Sequence is " + sequence);
        log.debug("Client is " + client);
    }/*www  . ja  va 2s  . c om*/
    if (partitions == null) {
        if (STARTED.equals(client.getState())) {
            try {
                partitionDataMutex.acquire();
                byte[] partitionData = client.getData().forPath(partitionDataPath);
                if (partitionData == null || partitionData.length == 0) {
                    Collection<Partition> existingPartitions = connectionFactory.getPartitions(topic);
                    Collection<Partition> listenedPartitions = !StringUtils.hasText(partitionList)
                            ? existingPartitions
                            : Arrays.asList(toPartitions(parseNumberList(partitionList)));
                    if (existingPartitions != listenedPartitions
                            && !existingPartitions.containsAll(listenedPartitions)) {
                        Collection<Partition> partitionsNotFound = new ArrayList<Partition>(listenedPartitions);
                        partitionsNotFound.removeAll(existingPartitions);
                        throw new BeanInitializationException(
                                "Configuration contains partitions that do not exist on the topic"
                                        + " or have unavailable leaders: "
                                        + StringUtils.collectionToCommaDelimitedString(partitionsNotFound));
                    }
                    final Map<Partition, BrokerAddress> leaders = connectionFactory
                            .getLeaders(listenedPartitions);
                    ArrayList<Partition> sortedPartitions = new ArrayList<Partition>(listenedPartitions);
                    Collections.sort(sortedPartitions, new Comparator<Partition>() {
                        @Override
                        public int compare(Partition o1, Partition o2) {
                            int i = leaders.get(o1).toString().compareTo(leaders.get(o2).toString());
                            if (i != 0) {
                                return i;
                            } else
                                return o1.getId() - o2.getId();
                        }
                    });
                    if (log.isDebugEnabled()) {
                        log.debug("Partitions: "
                                + StringUtils.collectionToCommaDelimitedString(sortedPartitions));
                    }
                    // calculate the minimum size of a partition group.
                    int minimumSize = sortedPartitions.size() / count;
                    int remainder = sortedPartitions.size() % count;
                    List<List<Integer>> partitionGroups = new ArrayList<List<Integer>>();
                    int cursor = 0;
                    for (int i = 0; i < count; i++) {
                        // first partitions will get an extra element
                        int partitionGroupSize = i < remainder ? minimumSize + 1 : minimumSize;
                        ArrayList<Integer> partitionGroup = new ArrayList<Integer>();
                        for (int j = 0; j < partitionGroupSize; j++) {
                            partitionGroup.add(sortedPartitions.get(cursor++).getId());
                        }
                        if (log.isDebugEnabled()) {
                            log.debug("Partitions for " + (i + 1) + " : "
                                    + StringUtils.collectionToCommaDelimitedString(partitionGroup));
                        }
                        partitionGroups.add(partitionGroup);
                    }
                    byte[] dataAsBytes = objectMapper.writer().writeValueAsBytes(partitionGroups);
                    if (log.isDebugEnabled()) {
                        log.debug(new String(dataAsBytes));
                    }
                    client.setData().forPath(partitionDataPath, dataAsBytes);
                    // the partition mapping is stored 0-based but sequence/count are 1-based
                    if (log.isDebugEnabled()) {
                        log.debug("Listening to: " + StringUtils
                                .collectionToCommaDelimitedString(partitionGroups.get(sequence - 1)));
                    }
                    partitions = toPartitions(partitionGroups.get(sequence - 1));
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug(new String(partitionData));
                    }
                    @SuppressWarnings("unchecked")
                    List<List<Integer>> partitionGroups = objectMapper.reader(List.class)
                            .readValue(partitionData);
                    // the partition mapping is stored 0-based but sequence/count are 1-based
                    if (log.isDebugEnabled()) {
                        log.debug("Listening to: " + StringUtils
                                .collectionToCommaDelimitedString(partitionGroups.get(sequence - 1)));
                    }
                    partitions = toPartitions(partitionGroups.get(sequence - 1));
                }
                return partitions;
            } finally {
                if (partitionDataMutex.isAcquiredInThisProcess()) {
                    partitionDataMutex.release();
                }
            }
        } else {
            throw new BeanInitializationException(
                    "Cannot connect to ZooKeeper, client state is " + client.getState());
        }
    } else {
        return partitions;
    }
}

From source file:org.springframework.security.access.annotation.SecuredAnnotationSecurityMetadataDefinitionSourceTests.java

public void testGenericsSuperclassDeclarationsAreIncludedWhenSubclassesOverride() {
    Method method = null;/*from  w  ww  .  j a  va  2s  .c om*/

    try {
        method = DepartmentServiceImpl.class.getMethod("someUserMethod3", new Class[] { Department.class });
    } catch (NoSuchMethodException unexpected) {
        fail("Should be a superMethod called 'someUserMethod3' on class!");
    }

    Collection<ConfigAttribute> attrs = mds.findAttributes(method, DepartmentServiceImpl.class);

    assertNotNull(attrs);

    if (logger.isDebugEnabled()) {
        logger.debug("attrs: " + StringUtils.collectionToCommaDelimitedString(attrs));
    }

    // expect 1 attribute
    assertTrue("Did not find 1 attribute", attrs.size() == 1);

    // should have 1 SecurityConfig
    for (ConfigAttribute sc : attrs) {
        assertEquals("Found an incorrect role", "ROLE_ADMIN", sc.getAttribute());
    }

    Method superMethod = null;

    try {
        superMethod = DepartmentServiceImpl.class.getMethod("someUserMethod3", new Class[] { Entity.class });
    } catch (NoSuchMethodException unexpected) {
        fail("Should be a superMethod called 'someUserMethod3' on class!");
    }

    Collection<ConfigAttribute> superAttrs = this.mds.findAttributes(superMethod, DepartmentServiceImpl.class);

    assertNotNull(superAttrs);

    if (logger.isDebugEnabled()) {
        logger.debug("superAttrs: " + StringUtils.collectionToCommaDelimitedString(superAttrs));
    }

    // This part of the test relates to SEC-274
    // expect 1 attribute
    assertEquals("Did not find 1 attribute", 1, superAttrs.size());
    // should have 1 SecurityConfig
    for (ConfigAttribute sc : superAttrs) {
        assertEquals("Found an incorrect role", "ROLE_ADMIN", sc.getAttribute());
    }
}

From source file:org.springframework.security.oauth2.provider.client.JdbcClientDetailsService.java

private Object[] getFieldsForUpdate(ClientDetails clientDetails) {
    String json = null;//from w  w w. jav a  2s  .c o m
    try {
        json = mapper.write(clientDetails.getAdditionalInformation());
    } catch (Exception e) {
        logger.warn("Could not serialize additional information: " + clientDetails, e);
    }
    return new Object[] {
            clientDetails.getResourceIds() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getResourceIds())
                    : null,
            clientDetails.getScope() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getScope())
                    : null,
            clientDetails.getAuthorizedGrantTypes() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorizedGrantTypes())
                    : null,
            clientDetails.getRegisteredRedirectUri() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getRegisteredRedirectUri())
                    : null,
            clientDetails.getAuthorities() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorities())
                    : null,
            clientDetails.getAccessTokenValiditySeconds(), clientDetails.getRefreshTokenValiditySeconds(), json,
            getAutoApproveScopes(clientDetails), clientDetails.getClientId() };
}

From source file:org.springframework.security.oauth2.provider.JdbcClientDetailsService.java

private Object[] getFieldsForUpdate(ClientDetails clientDetails) {
    String json = null;/*from   w ww. ja v  a 2  s  . c  om*/
    try {
        json = mapper.writeValueAsString(clientDetails.getAdditionalInformation());
    } catch (Exception e) {
        logger.warn("Could not serialize additional information: " + clientDetails, e);
    }
    return new Object[] {
            clientDetails.getResourceIds() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getResourceIds())
                    : null,
            clientDetails.getScope() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getScope())
                    : null,
            clientDetails.getAuthorizedGrantTypes() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorizedGrantTypes())
                    : null,
            clientDetails.getRegisteredRedirectUri() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getRegisteredRedirectUri())
                    : null,
            clientDetails.getAuthorities() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorities())
                    : null,
            clientDetails.getAccessTokenValiditySeconds(), clientDetails.getRefreshTokenValiditySeconds(), json,
            clientDetails.getClientId() };
}

From source file:org.springframework.social.spotify.api.SpotifyTrack.java

@Override
public String toString() {
    return "Track: " + this.getName() + " - Artists : "
            + StringUtils.collectionToCommaDelimitedString(this.getArtists()) + " | " + super.toString();
}

From source file:org.springframework.social.vkontakte.api.impl.SecureTemplate.java

public void sendNotification(Collection<String> userIds, String message) {
    requireAuthorization();/*from w w  w  . j av a2 s.  c  om*/
    Properties props = new Properties();
    props.put("user_ids", StringUtils.collectionToCommaDelimitedString(userIds));
    props.put("message", message);

    // see documentation under http://vk.com/dev/secure.sendNotification
    URI uri = makeOperationURL("secure.sendNotification", props, ApiVersion.VERSION_5_8);

    VKGenericResponse response = restTemplate.getForObject(uri, VKGenericResponse.class);
    checkForError(response);
}