mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-11 12:29:03 +00:00
perf[stream]: stream.toList() replaces collect(Collectors.toList())
This commit is contained in:
1 parent
4783a72703
commit
ac2d01e6fb
19 files changed
+34
-50
No files matched your search
+1
-2
@@ -26,7 +26,6 @@ import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 一致性hash负载均衡器,同一个session总是发到同一提供者
|
||||
@@ -104,7 +103,7 @@ public class ConsistentHashConsumerLoadBalancer extends AbstractConsumerLoadBala
|
||||
var sessionStringList = getSessionsByModule(module).stream()
|
||||
.map(session -> new Pair<>(session.getConsumerAttribute().toString(), session.getSid()))
|
||||
.sorted((a, b) -> a.getKey().compareTo(b.getKey()))
|
||||
.collect(Collectors.toList());
|
||||
.toList();;
|
||||
|
||||
var consistentHash = new ConsistentHash<>(sessionStringList, VIRTUAL_NODE_NUMS);
|
||||
var virtualNodeTreeMap = consistentHash.getVirtualNodeTreeMap();
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.lang.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author godotg
|
||||
@@ -109,7 +108,7 @@ public class RegisterVO {
|
||||
.map(it -> it.trim())
|
||||
.map(it -> it.split(StringUtils.HYPHEN))
|
||||
.map(it -> new ProviderModule(new ProtocolModule(Byte.parseByte(it[0]), it[1]), it[2]))
|
||||
.collect(Collectors.toList());
|
||||
.toList();;
|
||||
return modules;
|
||||
}
|
||||
|
||||
@@ -122,7 +121,7 @@ public class RegisterVO {
|
||||
.map(it -> it.trim())
|
||||
.map(it -> it.split(StringUtils.HYPHEN))
|
||||
.map(it -> new ConsumerModule(new ProtocolModule(Byte.parseByte(it[0]), it[1]), it[2], it[3]))
|
||||
.collect(Collectors.toList());
|
||||
.toList();;
|
||||
return modules;
|
||||
}
|
||||
|
||||
@@ -156,7 +155,7 @@ public class RegisterVO {
|
||||
builder.append(StringUtils.SPACE).append(StringUtils.VERTICAL_BAR).append(StringUtils.SPACE);
|
||||
var providerModules = providerConfig.getProviders().stream()
|
||||
.map(it -> StringUtils.joinWith(StringUtils.HYPHEN, it.getProtocolModule().getId(), it.getProtocolModule().getName(), it.getProvider()))
|
||||
.collect(Collectors.toList());
|
||||
.toList();;
|
||||
|
||||
// 服务提供者模块信息列表
|
||||
builder.append(StringUtils.format("provider:[{}]"
|
||||
@@ -169,7 +168,7 @@ public class RegisterVO {
|
||||
|
||||
var consumerModules = consumerConfig.getConsumers().stream()
|
||||
.map(it -> StringUtils.joinWith(StringUtils.HYPHEN, it.getProtocolModule().getId(), it.getProtocolModule().getName(), it.getLoadBalancer(), it.getConsumer()))
|
||||
.collect(Collectors.toList());
|
||||
.toList();;
|
||||
|
||||
// 服务消费者模块信息列表
|
||||
builder.append(StringUtils.format("consumer:[{}]"
|
||||
|
||||
@@ -596,7 +596,7 @@ public class ZookeeperRegistry implements IRegistry {
|
||||
try {
|
||||
var children = curator.getChildren().forPath(path).stream()
|
||||
.filter(it -> StringUtils.isNotBlank(it) && !"null".equals(it))
|
||||
.collect(Collectors.toList());
|
||||
.toList();;
|
||||
return children;
|
||||
} catch (Exception e) {
|
||||
logger.error("unknown exception", e);
|
||||
|
||||
@@ -16,7 +16,6 @@ import com.zfoo.protocol.collection.CollectionUtils;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author godotg
|
||||
@@ -70,7 +69,7 @@ public class HostAndPort {
|
||||
public static String toHostAndPortListStr(Collection<HostAndPort> list) {
|
||||
var urlList = list.stream()
|
||||
.map(it -> it.toHostAndPortStr())
|
||||
.collect(Collectors.toList());
|
||||
.toList();;
|
||||
return StringUtils.joinWith(StringUtils.COMMA, urlList.toArray());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author godotg
|
||||
@@ -34,7 +33,7 @@ public class SimpleCacheTest {
|
||||
var cache = SimpleCache.build(3000, 6000, 100, new Function<List<String>, List<Pair<String, String>>>() {
|
||||
@Override
|
||||
public List<Pair<String, String>> apply(List<String> keyList) {
|
||||
return keyList.stream().map(it -> new Pair<>(it, "new-" + it + "-value")).collect(Collectors.toList());
|
||||
return keyList.stream().map(it -> new Pair<>(it, "new-" + it + "-value")).toList();;
|
||||
}
|
||||
}, key -> "empty");
|
||||
|
||||
|
||||
Reference in new issue
Block a user