mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-06 04:24:08 +00:00
perf[stream]: stream.toList() replaces collect(Collectors.toList())
This commit is contained in:
+1
-1
@@ -103,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()))
|
||||
.toList();;
|
||||
.toList();
|
||||
|
||||
var consistentHash = new ConsistentHash<>(sessionStringList, VIRTUAL_NODE_NUMS);
|
||||
var virtualNodeTreeMap = consistentHash.getVirtualNodeTreeMap();
|
||||
|
||||
@@ -108,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]))
|
||||
.toList();;
|
||||
.toList();
|
||||
return modules;
|
||||
}
|
||||
|
||||
@@ -121,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]))
|
||||
.toList();;
|
||||
.toList();
|
||||
return modules;
|
||||
}
|
||||
|
||||
@@ -155,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()))
|
||||
.toList();;
|
||||
.toList();
|
||||
|
||||
// 服务提供者模块信息列表
|
||||
builder.append(StringUtils.format("provider:[{}]"
|
||||
@@ -168,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()))
|
||||
.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))
|
||||
.toList();;
|
||||
.toList();
|
||||
return children;
|
||||
} catch (Exception e) {
|
||||
logger.error("unknown exception", e);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class HostAndPort {
|
||||
public static String toHostAndPortListStr(Collection<HostAndPort> list) {
|
||||
var urlList = list.stream()
|
||||
.map(it -> it.toHostAndPortStr())
|
||||
.toList();;
|
||||
.toList();
|
||||
return StringUtils.joinWith(StringUtils.COMMA, urlList.toArray());
|
||||
}
|
||||
|
||||
|
||||
@@ -33,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")).toList();;
|
||||
return keyList.stream().map(it -> new Pair<>(it, "new-" + it + "-value")).toList();
|
||||
}
|
||||
}, key -> "empty");
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public class MongodbAccessor implements IAccessor {
|
||||
@SuppressWarnings("unchecked")
|
||||
var entityClazz = (Class<E>) entities.get(0).getClass();
|
||||
var collection = OrmContext.getOrmManager().getCollection(entityClazz);
|
||||
var ids = entities.stream().map(it -> (it).id()).toList();;
|
||||
var ids = entities.stream().map(it -> (it).id()).toList();
|
||||
collection.deleteMany(in("_id", ids));
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -230,7 +230,7 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
|
||||
|
||||
return new ReplaceOneModel<>(filter, it);
|
||||
})
|
||||
.toList();;
|
||||
.toList();
|
||||
|
||||
var result = collection.bulkWrite(batchList, new BulkWriteOptions().ordered(false));
|
||||
if (result.getModifiedCount() == batchList.size()) {
|
||||
@@ -261,7 +261,7 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
|
||||
return;
|
||||
}
|
||||
|
||||
var ids = updateList.stream().map(it -> it.id()).toList();;
|
||||
var ids = updateList.stream().map(it -> it.id()).toList();
|
||||
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -314,7 +314,7 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
|
||||
if (allPnodes.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return allPnodes.stream().map(it -> it.getEntity()).toList();;
|
||||
return allPnodes.stream().map(it -> it.getEntity()).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -84,7 +84,7 @@ public abstract class GenerateProtocolFile {
|
||||
var outsideGenerateProtocols = Arrays.stream(protocols)
|
||||
.filter(it -> Objects.nonNull(it))
|
||||
.filter(it -> generateProtocolFilter.test(it))
|
||||
.toList();;
|
||||
.toList();
|
||||
|
||||
// 需要生成的子协议,因为外层协议的内部有其它协议
|
||||
var insideGenerateProtocols = outsideGenerateProtocols.stream()
|
||||
@@ -92,7 +92,7 @@ public abstract class GenerateProtocolFile {
|
||||
.flatMap(it -> it.stream())
|
||||
.map(it -> protocols[it])
|
||||
.distinct()
|
||||
.toList();;
|
||||
.toList();
|
||||
|
||||
var allGenerateProtocols = new HashSet<IProtocolRegistration>();
|
||||
allGenerateProtocols.addAll(outsideGenerateProtocols);
|
||||
@@ -101,7 +101,7 @@ public abstract class GenerateProtocolFile {
|
||||
// 通过协议号,从小到大排序
|
||||
var allSortedGenerateProtocols = allGenerateProtocols.stream()
|
||||
.sorted((a, b) -> a.protocolId() - b.protocolId())
|
||||
.toList();;
|
||||
.toList();
|
||||
|
||||
// 解析协议的文档注释
|
||||
GenerateProtocolNote.initProtocolNote(allSortedGenerateProtocols);
|
||||
|
||||
@@ -116,7 +116,7 @@ public abstract class GenerateProtocolPath {
|
||||
|
||||
for (var i = splits.length; i > 0; i--) {
|
||||
builder.append("../");
|
||||
var path = StringUtils.joinWith(StringUtils.PERIOD, Arrays.stream(splits).limit(i).toList();.toArray());
|
||||
var path = StringUtils.joinWith(StringUtils.PERIOD, Arrays.stream(splits).limit(i).toList().toArray());
|
||||
if (relativePath.startsWith(path)) {
|
||||
builder.append(StringUtils.substringAfterFirst(relativePath, path).replaceAll(StringUtils.PERIOD_REGEX, StringUtils.SLASH));
|
||||
return builder.toString();
|
||||
@@ -180,7 +180,7 @@ public abstract class GenerateProtocolPath {
|
||||
var allChildren = protocolTreeNode.flatTreeNodes()
|
||||
.stream()
|
||||
.filter(it -> it.getData() != null)
|
||||
.toList();;
|
||||
.toList();
|
||||
var pathBefore = StringUtils.substringBeforeLast(protocolTreeNode.fullName(), StringUtils.PERIOD);
|
||||
for (var child : allChildren) {
|
||||
var protocolSimpleName = child.getData().protocolConstructor().getDeclaringClass().getSimpleName();
|
||||
|
||||
@@ -126,7 +126,7 @@ public abstract class EnhanceUtils {
|
||||
var allSubProtocolIds = ProtocolAnalysis.getAllSubProtocolIds(protocolId)
|
||||
.stream()
|
||||
.sorted((a, b) -> Short.compare(a, b))
|
||||
.toList();;
|
||||
.toList();
|
||||
|
||||
for (var subProtocolId : allSubProtocolIds) {
|
||||
var protocolRegistrationField = new CtField(classPool.get(IProtocolRegistration.class.getCanonicalName()), getProtocolRegistrationFieldNameByProtocolId(subProtocolId), enhanceClazz);
|
||||
|
||||
@@ -107,7 +107,7 @@ public class ProtocolAnalysis {
|
||||
}
|
||||
|
||||
// 通过指定类注册的协议,全部使用字节码增强
|
||||
var enhanceList = Arrays.stream(protocols).filter(Objects::nonNull).toList();;
|
||||
var enhanceList = Arrays.stream(protocols).filter(Objects::nonNull).toList();
|
||||
enhance(generateOperation, enhanceList);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class ProtocolAnalysis {
|
||||
|
||||
var relevantClassList = relevantClassSet.stream()
|
||||
.sorted((a, b) -> a.getCanonicalName().compareTo(b.getCanonicalName()))
|
||||
.toList();;
|
||||
.toList();
|
||||
|
||||
// 检查协议类是否合法
|
||||
var noProtocolIds = new ArrayList<Class<?>>();
|
||||
@@ -148,7 +148,7 @@ public class ProtocolAnalysis {
|
||||
}
|
||||
|
||||
// 通过指定类注册的协议,全部使用字节码增强
|
||||
var enhanceList = Arrays.stream(protocols).filter(Objects::nonNull).toList();;
|
||||
var enhanceList = Arrays.stream(protocols).filter(Objects::nonNull).toList();
|
||||
enhance(generateOperation, enhanceList);
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ public class ProtocolAnalysis {
|
||||
.stream()
|
||||
.sorted((a, b) -> a.getKey() - b.getKey())
|
||||
.map(Map.Entry::getValue)
|
||||
.toList();;
|
||||
.toList();
|
||||
notCompatibleFields.addAll(compatibleFields);
|
||||
return notCompatibleFields;
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ public abstract class GenerateCppUtils {
|
||||
// ValueOf()方法
|
||||
var valueOfParams = filedList.stream()
|
||||
.map(it -> StringUtils.format("{} {}", it.getKey(), it.getValue()))
|
||||
.toList();;
|
||||
.toList();
|
||||
var valueOfParamsStr = StringUtils.joinWith(StringUtils.COMMA + " ", valueOfParams.toArray());
|
||||
|
||||
var cppBuilder = new StringBuilder();
|
||||
|
||||
@@ -132,7 +132,7 @@ public abstract class GenerateJsUtils {
|
||||
var protocolId = registration.getId();
|
||||
var fields = registration.getFields();
|
||||
|
||||
var fieldValueOf = StringUtils.joinWith(", ", Arrays.stream(fields).map(it -> it.getName()).toList();.toArray());
|
||||
var fieldValueOf = StringUtils.joinWith(", ", Arrays.stream(fields).map(it -> it.getName()).toList().toArray());
|
||||
var fieldDefinitionBuilder = new StringBuilder();
|
||||
|
||||
for (var field : fields) {
|
||||
|
||||
@@ -135,7 +135,7 @@ public abstract class GenerateLuaUtils {
|
||||
var protocolId = registration.getId();
|
||||
var fields = registration.getFields();
|
||||
|
||||
var valueOfParams = StringUtils.joinWith(", ", Arrays.stream(fields).map(it -> it.getName()).toList();.toArray());
|
||||
var valueOfParams = StringUtils.joinWith(", ", Arrays.stream(fields).map(it -> it.getName()).toList().toArray());
|
||||
var luaBuilder = new StringBuilder();
|
||||
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
|
||||
@@ -318,7 +318,7 @@ public abstract class ReflectionUtils {
|
||||
.filter(it -> !Modifier.isStatic(it.getModifiers()))
|
||||
.filter(it -> !Modifier.isTransient(it.getModifiers()))
|
||||
.filter(it -> !it.isAnnotationPresent(Transient.class))
|
||||
.toList();;
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static String fieldToGetMethod(Class<?> clazz, Field field) {
|
||||
|
||||
@@ -119,7 +119,7 @@ public class ResourceInterpreter {
|
||||
}
|
||||
}
|
||||
}
|
||||
return fieldList.stream().map(it -> new FieldInfo(cellFieldMap.get(getExcelFieldName(it)), it)).toList();;
|
||||
return fieldList.stream().map(it -> new FieldInfo(cellFieldMap.get(getExcelFieldName(it)), it)).toList();
|
||||
}
|
||||
|
||||
private static class FieldInfo {
|
||||
|
||||
@@ -83,14 +83,14 @@ public abstract class ExportUtils {
|
||||
return FileUtils.getAllReadableFiles(new File(inputDir))
|
||||
.stream()
|
||||
.filter(it -> StorageEnum.isExcel(FileUtils.fileExtName(it.getName())))
|
||||
.toList();;
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static List<File> scanCsvFiles(String inputDir) {
|
||||
return FileUtils.getAllReadableFiles(new File(inputDir))
|
||||
.stream()
|
||||
.filter(it -> StorageEnum.getResourceEnumByType(FileUtils.fileExtName(it.getName())) == StorageEnum.CSV)
|
||||
.toList();;
|
||||
.toList();
|
||||
}
|
||||
|
||||
// 将class里的map自动赋值storage
|
||||
|
||||
Reference in New Issue
Block a user