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

The following examples show how to use org.springframework.util.StringUtils#commaDelimitedListToSet() . 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: GenericResourceRepository.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
private Collection<String> getProfilePaths(String profiles, String path) {
	Set<String> paths = new LinkedHashSet<>();
	for (String profile : StringUtils.commaDelimitedListToSet(profiles)) {
		if (!StringUtils.hasText(profile) || "default".equals(profile)) {
			paths.add(path);
		}
		else {
			String ext = StringUtils.getFilenameExtension(path);
			String file = path;
			if (ext != null) {
				ext = "." + ext;
				file = StringUtils.stripFilenameExtension(path);
			}
			else {
				ext = "";
			}
			paths.add(file + "-" + profile + ext);
		}
	}
	paths.add(path);
	return paths;
}
 
Example 2
Source File: TopicService.java    From pybbs with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public int vote(Topic topic, User user, HttpSession session) {
    String upIds = topic.getUpIds();
    // 将点赞用户id的字符串转成集合
    Set<String> strings = StringUtils.commaDelimitedListToSet(upIds);
    // 把新的点赞用户id添加进集合,这里用set,正好可以去重,如果集合里已经有用户的id了,那么这次动作被视为取消点赞
    Integer userScore = user.getScore();
    if (strings.contains(String.valueOf(user.getId()))) { // 取消点赞行为
        strings.remove(String.valueOf(user.getId()));
        userScore -= Integer.parseInt(systemConfigService.selectAllConfig().get("up_topic_score").toString());
    } else { // 点赞行为
        strings.add(String.valueOf(user.getId()));
        userScore += Integer.parseInt(systemConfigService.selectAllConfig().get("up_topic_score").toString());
    }
    // 再把这些id按逗号隔开组成字符串
    topic.setUpIds(StringUtils.collectionToCommaDelimitedString(strings));
    // 更新评论
    this.update(topic, null);
    // 增加用户积分
    user.setScore(userScore);
    userService.update(user);
    if (session != null) session.setAttribute("_user", user);
    return strings.size();
}
 
Example 3
Source File: CommentService.java    From pybbs with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public int vote(Comment comment, User user, HttpSession session) {
    String upIds = comment.getUpIds();
    // 将点赞用户id的字符串转成集合
    Set<String> strings = StringUtils.commaDelimitedListToSet(upIds);
    // 把新的点赞用户id添加进集合,这里用set,正好可以去重,如果集合里已经有用户的id了,那么这次动作被视为取消点赞
    Integer userScore = user.getScore();
    if (strings.contains(String.valueOf(user.getId()))) { // 取消点赞行为
        strings.remove(String.valueOf(user.getId()));
        userScore -= Integer.parseInt(systemConfigService.selectAllConfig().get("up_comment_score").toString());
    } else { // 点赞行为
        strings.add(String.valueOf(user.getId()));
        userScore += Integer.parseInt(systemConfigService.selectAllConfig().get("up_comment_score").toString());
    }
    // 再把这些id按逗号隔开组成字符串
    comment.setUpIds(StringUtils.collectionToCommaDelimitedString(strings));
    // 更新评论
    this.update(comment);
    // 增加用户积分
    user.setScore(userScore);
    userService.update(user);
    if (session != null) session.setAttribute("_user", user);
    return strings.size();
}
 
Example 4
Source File: BackplaneConfiguration.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void initialize() {
    String cassandraHosts = env.getProperty("ea.cassandra.hosts","localhost:9042");
    String cassandraKeyspaceName = env.getProperty("ea.cassandra.keyspace","\"ElasticActors\"");
    Integer cassandraPort = env.getProperty("ea.cassandra.port", Integer.class, 9042);

    Set<String> hostSet = StringUtils.commaDelimitedListToSet(cassandraHosts);

    String[] contactPoints = new String[hostSet.size()];
    int i=0;
    for (String host : hostSet) {
        if(host.contains(":")) {
            contactPoints[i] = host.substring(0,host.indexOf(":"));
        } else {
            contactPoints[i] = host;
        }
        i+=1;
    }

    List<InetSocketAddress> contactPointAddresses = Arrays.stream(contactPoints)
            .map(host -> new InetSocketAddress(host, cassandraPort))
            .collect(Collectors.toList());

    DriverConfigLoader driverConfigLoader = DriverConfigLoader.programmaticBuilder()
            .withDuration(DefaultDriverOption.HEARTBEAT_INTERVAL, Duration.ofSeconds(60))
            .withString(DefaultDriverOption.REQUEST_CONSISTENCY, ConsistencyLevel.QUORUM.name())
            .withString(DefaultDriverOption.RETRY_POLICY_CLASS, "DefaultRetryPolicy")
            .withString(DefaultDriverOption.RECONNECTION_POLICY_CLASS, "ConstantReconnectionPolicy")
            .withDuration(DefaultDriverOption.RECONNECTION_BASE_DELAY, Duration.ofSeconds(env.getProperty("ea.cassandra.retryDownedHostsDelayInSeconds",Integer.class,1)))
            .withString(DefaultDriverOption.LOAD_BALANCING_POLICY_CLASS, "DcInferringLoadBalancingPolicy")
            .build();


    cassandraSession = CqlSession.builder()
            .addContactPoints(contactPointAddresses)
            .withConfigLoader(driverConfigLoader)
            .withKeyspace(cassandraKeyspaceName)
            .build();
}
 
Example 5
Source File: BackplaneConfiguration.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void initialize() {
    String cassandraHosts = env.getProperty("ea.cassandra.hosts","localhost:9042");
    String cassandraClusterName = env.getProperty("ea.cassandra.cluster","ElasticActorsCluster");
    String cassandraKeyspaceName = env.getProperty("ea.cassandra.keyspace","\"ElasticActors\"");
    Integer cassandraPort = env.getProperty("ea.cassandra.port", Integer.class, 9042);

    Set<String> hostSet = StringUtils.commaDelimitedListToSet(cassandraHosts);

    String[] contactPoints = new String[hostSet.size()];
    int i=0;
    for (String host : hostSet) {
        if(host.contains(":")) {
            contactPoints[i] = host.substring(0,host.indexOf(":"));
        } else {
            contactPoints[i] = host;
        }
        i+=1;
    }

    PoolingOptions poolingOptions = new PoolingOptions();
    poolingOptions.setHeartbeatIntervalSeconds(60);
    poolingOptions.setConnectionsPerHost(HostDistance.LOCAL, 2, env.getProperty("ea.cassandra.maxActive",Integer.class,Runtime.getRuntime().availableProcessors() * 3));
    poolingOptions.setPoolTimeoutMillis(2000);

    Cluster cassandraCluster =
            Cluster.builder().withClusterName(cassandraClusterName)
                    .addContactPoints(contactPoints)
                    .withPort(cassandraPort)
            .withLoadBalancingPolicy(new RoundRobinPolicy())
            .withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE))
            .withPoolingOptions(poolingOptions)
            .withReconnectionPolicy(new ConstantReconnectionPolicy(env.getProperty("ea.cassandra.retryDownedHostsDelayInSeconds",Integer.class,1) * 1000))
            .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.QUORUM)).build();

    this.cassandraSession = cassandraCluster.connect(cassandraKeyspaceName);

    
}
 
Example 6
Source File: SessionComponent.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void setClusterableTools(String clusterableToolList) {
	Set<?> newTools = StringUtils.commaDelimitedListToSet(clusterableToolList);
	this.clusterableTools.clear();
	for (Object o: newTools) {
		if (o instanceof java.lang.String) {
			this.clusterableTools.add((String)o);
		} else {
			log.error("SessionManager.setClusterableTools(String) unable to set value: "+o);
		}
	}
}
 
Example 7
Source File: ConfigurationPropertiesRebinder.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@ManagedAttribute
public Set<String> getNeverRefreshable() {
	String neverRefresh = this.applicationContext.getEnvironment().getProperty(
			"spring.cloud.refresh.never-refreshable",
			"com.zaxxer.hikari.HikariDataSource");
	return StringUtils.commaDelimitedListToSet(neverRefresh);
}
 
Example 8
Source File: SessionComponent.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void setClusterableTools(String clusterableToolList) {
	Set<?> newTools = StringUtils.commaDelimitedListToSet(clusterableToolList);
	this.clusterableTools.clear();
	for (Object o: newTools) {
		if (o instanceof java.lang.String) {
			this.clusterableTools.add((String)o);
		} else {
			log.error("SessionManager.setClusterableTools(String) unable to set value: "+o);
		}
	}
}
 
Example 9
Source File: CommandlineRunner.java    From OTX-Java-SDK with Apache License 2.0 5 votes vote down vote up
private static Set<IndicatorType> parseTypes(String types) throws ParseException {
    Set<String> strings = StringUtils.commaDelimitedListToSet(types);
    Set<IndicatorType> ret = new HashSet<>();
    for (String string : strings) {
        try {
            ret.add(IndicatorType.valueOf(string.toUpperCase()));
        } catch (IllegalArgumentException e) {
            throw new ParseException("Error parsing enum type: " +string);
        }
    }
    return ret;
}
 
Example 10
Source File: BaseClientDetails.java    From MaxKey with Apache License 2.0 5 votes vote down vote up
public BaseClientDetails(String clientId, String resourceIds,
		String scopes, String grantTypes, String authorities,
		String redirectUris) {

	this.clientId = clientId;

	if (StringUtils.hasText(resourceIds)) {
		Set<String> resources = StringUtils
				.commaDelimitedListToSet(resourceIds);
		if (!resources.isEmpty()) {
			this.resourceIds = resources;
		}
	}

	if (StringUtils.hasText(scopes)) {
		Set<String> scopeList = StringUtils.commaDelimitedListToSet(scopes);
		if (!scopeList.isEmpty()) {
			this.scope = scopeList;
		}
	}

	if (StringUtils.hasText(grantTypes)) {
		this.authorizedGrantTypes = StringUtils
				.commaDelimitedListToSet(grantTypes);
	} else {
		this.authorizedGrantTypes = new HashSet<String>(Arrays.asList(
				"authorization_code", "refresh_token"));
	}

	if (StringUtils.hasText(authorities)) {
		this.authorities = AuthorityUtils
				.commaSeparatedStringToAuthorityList(authorities);
	}

	if (StringUtils.hasText(redirectUris)) {
		this.registeredRedirectUris = StringUtils
				.commaDelimitedListToSet(redirectUris);
	}
}
 
Example 11
Source File: RepoCommand.java    From mojito with Apache License 2.0 5 votes vote down vote up
/**
 * Extract {@link IntegrityChecker} Set from
 * {@link RepoCreateCommand#integrityCheckParam} to prep for
 * {@link Repository} creation
 *
 * @param integrityCheckParam
 * @param doPrint
 * @return
 */
protected Set<IntegrityChecker> extractIntegrityCheckersFromInput(String integrityCheckParam, boolean doPrint) throws CommandException {
    Set<IntegrityChecker> integrityCheckers = null;
    if (integrityCheckParam != null) {
        integrityCheckers = new HashSet<>();
        Set<String> integrityCheckerParams = StringUtils.commaDelimitedListToSet(integrityCheckParam);
        if (doPrint) {
            consoleWriter.a("Extracted Integrity Checkers").println();
        }

        for (String integrityCheckerParam : integrityCheckerParams) {
            String[] param = StringUtils.delimitedListToStringArray(integrityCheckerParam, ":");
            if (param.length != 2) {
                throw new ParameterException("Invalid integrity checker format [" + integrityCheckerParam + "]");
            }
            String fileExtension = param[0];
            String checkerType = param[1];
            IntegrityChecker integrityChecker = new IntegrityChecker();
            integrityChecker.setAssetExtension(fileExtension);
            try {
                integrityChecker.setIntegrityCheckerType(IntegrityCheckerType.valueOf(checkerType));
            } catch (IllegalArgumentException ex) {
                throw new ParameterException("Invalid integrity checker type [" + checkerType + "]");
            }

            if (doPrint) {
                consoleWriter.fg(Ansi.Color.BLUE).a("-- file extension = ").fg(Ansi.Color.GREEN).a(integrityChecker.getAssetExtension()).println();
                consoleWriter.fg(Ansi.Color.BLUE).a("-- checker type = ").fg(Ansi.Color.GREEN).a(integrityChecker.getIntegrityCheckerType().toString()).println();
            }

            integrityCheckers.add(integrityChecker);
        }
    }
    return integrityCheckers;
}
 
Example 12
Source File: PackageReaderTests.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
private Set<String> convertToSet(String tags) {
	Set<String> initialSet = StringUtils.commaDelimitedListToSet(tags);

	Set<String> setToReturn = initialSet.stream()
			.map(StringUtils::trimAllWhitespace)
			.collect(Collectors.toSet());

	return setToReturn;
}
 
Example 13
Source File: OpenClientDetails.java    From open-cloud with MIT License 5 votes vote down vote up
public OpenClientDetails(String clientId, String resourceIds,
                         String scopes, String grantTypes, String authorities,
                         String redirectUris) {

    this.clientId = clientId;

    if (StringUtils.hasText(resourceIds)) {
        Set<String> resources = StringUtils
                .commaDelimitedListToSet(resourceIds);
        if (!resources.isEmpty()) {
            this.resourceIds = resources;
        }
    }

    if (StringUtils.hasText(scopes)) {
        Set<String> scopeList = StringUtils.commaDelimitedListToSet(scopes);
        if (!scopeList.isEmpty()) {
            this.scope = scopeList;
        }
    }

    if (StringUtils.hasText(grantTypes)) {
        this.authorizedGrantTypes = StringUtils
                .commaDelimitedListToSet(grantTypes);
    } else {
        this.authorizedGrantTypes = new HashSet<String>(Arrays.asList(
                "authorization_code", "refresh_token"));
    }

    if (StringUtils.hasText(authorities)) {
        this.authorities = AuthorityUtils
                .commaSeparatedStringToAuthorityList(authorities);
    }

    if (StringUtils.hasText(redirectUris)) {
        this.registeredRedirectUris = StringUtils
                .commaDelimitedListToSet(redirectUris);
    }
}
 
Example 14
Source File: MarathonAppDeployer.java    From spring-cloud-deployer-mesos with Apache License 2.0 4 votes vote down vote up
private Collection<String> deduceUris(AppDeploymentRequest request) {
	Set<String> additional = StringUtils.commaDelimitedListToSet(request.getDeploymentProperties().get(prefix("uris")));
	HashSet<String> result = new HashSet<>(additional);
	result.addAll(properties.getUris());
	return result;
}
 
Example 15
Source File: StompHeaderAccessor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public Set<String> getAcceptVersion() {
	String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER);
	return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.emptySet());
}
 
Example 16
Source File: StompHeaderAccessor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public Set<String> getAcceptVersion() {
	String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER);
	return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.<String>emptySet());
}
 
Example 17
Source File: BaseModel.java    From pybbs with GNU Affero General Public License v3.0 4 votes vote down vote up
public Set<String> getUpIds(String upIds) {
    if (StringUtils.isEmpty(upIds)) return new HashSet<>();
    return StringUtils.commaDelimitedListToSet(upIds);
}
 
Example 18
Source File: DubboHealthIndicator.java    From dubbo-spring-boot-project with Apache License 2.0 4 votes vote down vote up
private Set<String> getStatusCheckerNames(ProviderConfig providerConfig) {
    String status = providerConfig.getStatus();
    return StringUtils.commaDelimitedListToSet(status);
}
 
Example 19
Source File: DubboHealthIndicator.java    From dubbo-spring-boot-project with Apache License 2.0 4 votes vote down vote up
private Set<String> getStatusCheckerNames(ProtocolConfig protocolConfig) {
    String status = protocolConfig.getStatus();
    return StringUtils.commaDelimitedListToSet(status);
}
 
Example 20
Source File: StompHeaderAccessor.java    From java-technology-stack with MIT License 4 votes vote down vote up
public Set<String> getAcceptVersion() {
	String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER);
	return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.emptySet());
}