下面列出了org.springframework.util.StringUtils#commaDelimitedListToSet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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();
}
@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;
}
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);
}
}
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;
}
/**
* 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;
}
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);
}
}
@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();
}
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;
}
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);
}
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);
}
}
}
@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);
}
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;
}
public Set<String> getUpIds(String upIds) {
if (StringUtils.isEmpty(upIds)) return new HashSet<>();
return StringUtils.commaDelimitedListToSet(upIds);
}