Java Code Examples for org.springframework.util.StringUtils#commaDelimitedListToSet()
The following examples show how to use
org.springframework.util.StringUtils#commaDelimitedListToSet() .
These examples are extracted from open source projects.
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 Project: pybbs File: CommentService.java License: GNU Affero General Public License v3.0 | 6 votes |
@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 2
Source Project: pybbs File: TopicService.java License: GNU Affero General Public License v3.0 | 6 votes |
@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 Project: spring-cloud-config File: GenericResourceRepository.java License: Apache License 2.0 | 6 votes |
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 4
Source Project: open-cloud File: OpenClientDetails.java License: MIT License | 5 votes |
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 5
Source Project: spring-cloud-skipper File: PackageReaderTests.java License: Apache License 2.0 | 5 votes |
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 6
Source Project: mojito File: RepoCommand.java License: Apache License 2.0 | 5 votes |
/** * 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 7
Source Project: MaxKey File: BaseClientDetails.java License: Apache License 2.0 | 5 votes |
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 8
Source Project: elasticactors File: BackplaneConfiguration.java License: Apache License 2.0 | 5 votes |
@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 9
Source Project: OTX-Java-SDK File: CommandlineRunner.java License: Apache License 2.0 | 5 votes |
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 Project: sakai File: SessionComponent.java License: Educational Community License v2.0 | 5 votes |
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 11
Source Project: spring-cloud-commons File: ConfigurationPropertiesRebinder.java License: Apache License 2.0 | 5 votes |
@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 12
Source Project: sakai File: SessionComponent.java License: Educational Community License v2.0 | 5 votes |
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 13
Source Project: elasticactors File: BackplaneConfiguration.java License: Apache License 2.0 | 5 votes |
@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 14
Source Project: spring-analysis-note File: StompHeaderAccessor.java License: MIT License | 4 votes |
public Set<String> getAcceptVersion() { String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER); return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.emptySet()); }
Example 15
Source Project: java-technology-stack File: StompHeaderAccessor.java License: MIT License | 4 votes |
public Set<String> getAcceptVersion() { String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER); return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.emptySet()); }
Example 16
Source Project: dubbo-spring-boot-project File: DubboHealthIndicator.java License: Apache License 2.0 | 4 votes |
private Set<String> getStatusCheckerNames(ProtocolConfig protocolConfig) { String status = protocolConfig.getStatus(); return StringUtils.commaDelimitedListToSet(status); }
Example 17
Source Project: dubbo-spring-boot-project File: DubboHealthIndicator.java License: Apache License 2.0 | 4 votes |
private Set<String> getStatusCheckerNames(ProviderConfig providerConfig) { String status = providerConfig.getStatus(); return StringUtils.commaDelimitedListToSet(status); }
Example 18
Source Project: spring4-understanding File: StompHeaderAccessor.java License: Apache License 2.0 | 4 votes |
public Set<String> getAcceptVersion() { String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER); return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.<String>emptySet()); }
Example 19
Source Project: spring-cloud-deployer-mesos File: MarathonAppDeployer.java License: Apache License 2.0 | 4 votes |
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 20
Source Project: pybbs File: BaseModel.java License: GNU Affero General Public License v3.0 | 4 votes |
public Set<String> getUpIds(String upIds) { if (StringUtils.isEmpty(upIds)) return new HashSet<>(); return StringUtils.commaDelimitedListToSet(upIds); }