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

The following examples show how to use org.springframework.util.StringUtils#collectionToCommaDelimitedString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReactorNettyWebSocketClient.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public Mono<Void> execute(URI url, HttpHeaders requestHeaders, WebSocketHandler handler) {
	String protocols = StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols());
	return getHttpClient()
			.headers(nettyHeaders -> setNettyHeaders(requestHeaders, nettyHeaders))
			.websocket(protocols, getMaxFramePayloadLength())
			.uri(url.toString())
			.handle((inbound, outbound) -> {
				HttpHeaders responseHeaders = toHttpHeaders(inbound);
				String protocol = responseHeaders.getFirst("Sec-WebSocket-Protocol");
				HandshakeInfo info = new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol);
				NettyDataBufferFactory factory = new NettyDataBufferFactory(outbound.alloc());
				WebSocketSession session = new ReactorNettyWebSocketSession(
						inbound, outbound, info, factory, getMaxFramePayloadLength());
				if (logger.isDebugEnabled()) {
					logger.debug("Started session '" + session.getId() + "' for " + url);
				}
				return handler.handle(session).checkpoint(url + " [ReactorNettyWebSocketClient]");
			})
			.doOnRequest(n -> {
				if (logger.isDebugEnabled()) {
					logger.debug("Connecting to " + url);
				}
			})
			.next();
}
 
Example 2
Source File: CommandLinePropertySource.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * This implementation first checks to see if the name specified is the special
 * {@linkplain #setNonOptionArgsPropertyName(String) "non-option arguments" property},
 * and if so delegates to the abstract {@link #getNonOptionArgs()} method. If so
 * and the collection of non-option arguments is empty, this method returns {@code
 * null}. If not empty, it returns a comma-separated String of all non-option
 * arguments. Otherwise delegates to and returns the result of the abstract {@link
 * #getOptionValues(String)} method.
 */
@Override
public final String getProperty(String name) {
	if (this.nonOptionArgsPropertyName.equals(name)) {
		Collection<String> nonOptionArguments = this.getNonOptionArgs();
		if (nonOptionArguments.isEmpty()) {
			return null;
		}
		else {
			return StringUtils.collectionToCommaDelimitedString(nonOptionArguments);
		}
	}
	Collection<String> optionValues = this.getOptionValues(name);
	if (optionValues == null) {
		return null;
	}
	else {
		return StringUtils.collectionToCommaDelimitedString(optionValues);
	}
}
 
Example 3
Source File: StaticListableBeanFactory.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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
Source File: SpringApplicationContextInitializer.java    From spring-music with Apache License 2.0 6 votes vote down vote up
private String[] getActiveProfile(ConfigurableEnvironment appEnvironment) {
    List<String> serviceProfiles = new ArrayList<>();

    for (String profile : appEnvironment.getActiveProfiles()) {
        if (validLocalProfiles.contains(profile)) {
            serviceProfiles.add(profile);
        }
    }

    if (serviceProfiles.size() > 1) {
        throw new IllegalStateException("Only one active Spring profile may be set among the following: " +
                validLocalProfiles.toString() + ". " +
                "These profiles are active: [" +
                StringUtils.collectionToCommaDelimitedString(serviceProfiles) + "]");
    }

    if (serviceProfiles.size() > 0) {
        return createProfileNames(serviceProfiles.get(0), "local");
    }

    return null;
}
 
Example 5
Source File: SearchOperations.java    From rug-cli with GNU General Public License v3.0 5 votes vote down vote up
private String toCommaSeperatedList(Properties tags) {
    if (tags.isEmpty()) {
        return "";
    }
    else {
        return StringUtils.collectionToCommaDelimitedString(
                tags.keySet().stream().map(k -> "\"" + k + "\"").collect(Collectors.toList()));
    }
}
 
Example 6
Source File: AppsOAuth20Details.java    From MaxKey with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
public AppsOAuth20Details(Apps application, BaseClientDetails baseClientDetails) {
    super();
    this.id = application.getId();
    this.setName(application.getName());
    this.setLoginUrl(application.getLoginUrl());
    this.setCategory(application.getCategory());
    this.setProtocol(application.getProtocol());
    this.setIcon(application.getIcon());
    this.clientId = application.getId();

    this.setSortIndex(application.getSortIndex());
    this.setVendor(application.getVendor());
    this.setVendorUrl(application.getVendorUrl());

    this.clientSecret = baseClientDetails.getClientSecret();
    this.scope = baseClientDetails.getScope().toString();
    this.resourceIds = baseClientDetails.getResourceIds().toString();
    this.authorizedGrantTypes = baseClientDetails.getAuthorizedGrantTypes().toString();
    this.registeredRedirectUris = StringUtils
            .collectionToCommaDelimitedString(baseClientDetails.getRegisteredRedirectUri());
    this.authorities = baseClientDetails.getAuthorities().toString();
    this.accessTokenValiditySeconds = baseClientDetails.getAccessTokenValiditySeconds();
    this.refreshTokenValiditySeconds = baseClientDetails.getRefreshTokenValiditySeconds();
    this.approvalPrompt = baseClientDetails.isAutoApprove("all") + "";

    this.idTokenEncryptedAlgorithm = baseClientDetails.getIdTokenEncryptedAlgorithm();
    this.idTokenEncryptionMethod = baseClientDetails.getIdTokenEncryptionMethod();
    this.idTokenSigningAlgorithm = baseClientDetails.getIdTokenSigningAlgorithm();

    this.userInfoEncryptedAlgorithm = baseClientDetails.getUserInfoEncryptedAlgorithm();
    this.userInfoEncryptionMethod = baseClientDetails.getUserInfoEncryptionMethod();
    this.userInfoSigningAlgorithm = baseClientDetails.getUserInfoSigningAlgorithm();

    this.jwksUri = baseClientDetails.getJwksUri();

}
 
Example 7
Source File: NoUniqueBeanDefinitionException.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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)
 * @since 5.1
 */
public NoUniqueBeanDefinitionException(ResolvableType type, Collection<String> beanNamesFound) {
	super(type, "expected single matching bean but found " + beanNamesFound.size() + ": " +
			StringUtils.collectionToCommaDelimitedString(beanNamesFound));
	this.numberOfBeansFound = beanNamesFound.size();
	this.beanNamesFound = beanNamesFound;
}
 
Example 8
Source File: TopicController.java    From pybbs with GNU Affero General Public License v3.0 5 votes vote down vote up
@GetMapping("/edit/{id}")
public String edit(@PathVariable Integer id, Model model) {
    Topic topic = topicService.selectById(id);
    Assert.isTrue(topic.getUserId().equals(getUser().getId()), "谁给你的权限修改别人的话题的?");
    // 查询话题的标签
    List<Tag> tagList = tagService.selectByTopicId(id);
    // 将标签集合转成逗号隔开的字符串
    String tags = StringUtils.collectionToCommaDelimitedString(tagList.stream().map(Tag::getName).collect(Collectors
            .toList()));

    model.addAttribute("topic", topic);
    model.addAttribute("tags", tags);
    return render("topic/edit");
}
 
Example 9
Source File: FieldUtil.java    From watchdog-spring-boot-starter with MIT License 5 votes vote down vote up
public static String getAutoApproveScopes(ClientDetails clientDetails) {
    if (clientDetails.isAutoApprove("true")) {
        return "true"; // all scopes autoapproved
    }
    Set<String> scopes = new HashSet<String>();
    for (String scope : clientDetails.getScope()) {
        if (clientDetails.isAutoApprove(scope)) {
            scopes.add(scope);
        }
    }
    return StringUtils.collectionToCommaDelimitedString(scopes);
}
 
Example 10
Source File: SpringApplicationContextInitializer.java    From spring-music with Apache License 2.0 5 votes vote down vote up
public String[] getCloudProfile(Cloud cloud) {
    if (cloud == null) {
        return null;
    }

    List<String> profiles = new ArrayList<>();

    List<ServiceInfo> serviceInfos = cloud.getServiceInfos();

    logger.info("Found serviceInfos: " + StringUtils.collectionToCommaDelimitedString(serviceInfos));

    for (ServiceInfo serviceInfo : serviceInfos) {
        if (serviceTypeToProfileName.containsKey(serviceInfo.getClass())) {
            profiles.add(serviceTypeToProfileName.get(serviceInfo.getClass()));
        }
    }

    if (profiles.size() > 1) {
        throw new IllegalStateException(
                "Only one service of the following types may be bound to this application: " +
                        serviceTypeToProfileName.values().toString() + ". " +
                        "These services are bound to the application: [" +
                        StringUtils.collectionToCommaDelimitedString(profiles) + "]");
    }

    if (profiles.size() > 0) {
        return createProfileNames(profiles.get(0), "cloud");
    }

    return null;
}
 
Example 11
Source File: GeodePoolsHealthIndicator.java    From spring-boot-data-geode with Apache License 2.0 5 votes vote down vote up
private String toCommaDelimitedHostAndPortsString(List<InetSocketAddress> socketAddresses) {

		return StringUtils.collectionToCommaDelimitedString(nullSafeList(socketAddresses).stream()
			.filter(Objects::nonNull)
			.map(socketAddress -> String.format("%1$s:%2$d", socketAddress.getHostName(), socketAddress.getPort()))
			.collect(Collectors.toList()));
	}
 
Example 12
Source File: ContextInitializer.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String[] getCloudProfiles(Cloud cloud) {
    if (cloud == null) {
        return null;
    }

    List<String> profiles = new ArrayList<>();

    List<ServiceInfo> serviceInfos = cloud.getServiceInfos();

    LOGGER.info("Found serviceInfos: " + StringUtils.collectionToCommaDelimitedString(serviceInfos));

    for (ServiceInfo serviceInfo : serviceInfos) {
        if (serviceTypeToProfileName.containsKey(serviceInfo.getClass())) {
            profiles.add(serviceTypeToProfileName.get(serviceInfo.getClass()));
        }
    }

    if (profiles.size() > 1) {
        throw new IllegalStateException(
                "Only one service of the following types may be bound to this application: " +
                        serviceTypeToProfileName.values().toString() + ". " +
                        "These services are bound to the application: [" +
                        StringUtils.collectionToCommaDelimitedString(profiles) + "]");
    }

    if (profiles.size() > 0) {
        return createProfileNames(profiles.get(0), "cloud");
    }

    return null;
}
 
Example 13
Source File: GenericConversionService.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String toString() {
	return StringUtils.collectionToCommaDelimitedString(this.converters);
}
 
Example 14
Source File: GenericConversionService.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public String toString() {
	return StringUtils.collectionToCommaDelimitedString(this.converters);
}
 
Example 15
Source File: SyncRecord.java    From ecs-sync with Apache License 2.0 4 votes vote down vote up
public static String selectErrors(String tableName) {
    return "select " + StringUtils.collectionToCommaDelimitedString(ALL_FIELDS)
            + " from " + tableName + " where status = '" + ObjectStatus.Error.getValue() + "'";
}
 
Example 16
Source File: ClusterPreValidator.java    From ankush with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Method to check process lists.
 * 
 * @param username
 * @param hostname
 * @param authUsingPassword
 * @param authInfo
 * @return
 */
private Status checkProcessList(String username, String hostname,
		boolean authUsingPassword, String authInfo) {
	String processList = "";
	String message = null;
	try {
		processList = SSHUtils.getCommandOutput("jps", hostname, username,
				authInfo, authUsingPassword);
	} catch (Exception e) {
		message = e.getMessage();
		logger.error(message, e);
	}

	List<String> processes = null;
	if ((processList == null) || processList.isEmpty()) {
		processes = new ArrayList<String>();
	} else {
		processes = new ArrayList<String>(Arrays.asList(processList
				.split("\n")));
	}

	List<String> processLists = new ArrayList<String>();
	for (String process : processes) {
		if (!(process.contains("Jps") || process
				.contains(AgentDeployer.ANKUSH_SERVER_PROCSS_NAME))) {
			String[] processArray = process.split("\\ ");
			if (processArray.length == 2) {
				processLists.add(process.split("\\ ")[1]);
			}
		}
	}

	if (processLists.isEmpty()) {
		return new Status("JPS process list", OK);
	} else {
		message = StringUtils
				.collectionToCommaDelimitedString(processLists)
				+ " already running";
		return new Status("JPS process list", message, WARNING);
	}
}
 
Example 17
Source File: GenericConversionService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return StringUtils.collectionToCommaDelimitedString(this.converters);
}
 
Example 18
Source File: GenericConversionService.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public String toString() {
	return StringUtils.collectionToCommaDelimitedString(this.converters);
}
 
Example 19
Source File: NoUniqueBeanDefinitionException.java    From blog_demos with Apache License 2.0 2 votes vote down vote up
/**
 * 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 20
Source File: NoUniqueBeanDefinitionException.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}