org.springframework.util.StringUtils#commaDelimitedListToSet ( )源码实例Demo

下面列出了org.springframework.util.StringUtils#commaDelimitedListToSet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pybbs   文件: CommentService.java
@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();
}
 
源代码2 项目: pybbs   文件: TopicService.java
@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();
}
 
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;
}
 
源代码4 项目: open-cloud   文件: OpenClientDetails.java
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);
    }
}
 
源代码5 项目: spring-cloud-skipper   文件: PackageReaderTests.java
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;
}
 
源代码6 项目: mojito   文件: RepoCommand.java
/**
 * 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;
}
 
源代码7 项目: MaxKey   文件: BaseClientDetails.java
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);
	}
}
 
源代码8 项目: elasticactors   文件: BackplaneConfiguration.java
@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();
}
 
源代码9 项目: OTX-Java-SDK   文件: CommandlineRunner.java
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;
}
 
源代码10 项目: sakai   文件: SessionComponent.java
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);
		}
	}
}
 
@ManagedAttribute
public Set<String> getNeverRefreshable() {
	String neverRefresh = this.applicationContext.getEnvironment().getProperty(
			"spring.cloud.refresh.never-refreshable",
			"com.zaxxer.hikari.HikariDataSource");
	return StringUtils.commaDelimitedListToSet(neverRefresh);
}
 
源代码12 项目: sakai   文件: SessionComponent.java
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);
		}
	}
}
 
源代码13 项目: elasticactors   文件: BackplaneConfiguration.java
@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);

    
}
 
源代码14 项目: spring-analysis-note   文件: StompHeaderAccessor.java
public Set<String> getAcceptVersion() {
	String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER);
	return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.emptySet());
}
 
public Set<String> getAcceptVersion() {
	String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER);
	return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.emptySet());
}
 
private Set<String> getStatusCheckerNames(ProtocolConfig protocolConfig) {
    String status = protocolConfig.getStatus();
    return StringUtils.commaDelimitedListToSet(status);
}
 
private Set<String> getStatusCheckerNames(ProviderConfig providerConfig) {
    String status = providerConfig.getStatus();
    return StringUtils.commaDelimitedListToSet(status);
}
 
public Set<String> getAcceptVersion() {
	String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER);
	return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.<String>emptySet());
}
 
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;
}
 
源代码20 项目: pybbs   文件: BaseModel.java
public Set<String> getUpIds(String upIds) {
    if (StringUtils.isEmpty(upIds)) return new HashSet<>();
    return StringUtils.commaDelimitedListToSet(upIds);
}