Skip to content

Commit

Permalink
ref[storage]: refactor lambda of storage
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Oct 21, 2023
1 parent a590553 commit b64a7a4
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions storage/src/main/java/com/zfoo/storage/manager/AbstractStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.zfoo.protocol.collection.CollectionUtils;
import com.zfoo.protocol.util.*;
import com.zfoo.storage.anno.Index;
import com.zfoo.storage.interpreter.ResourceInterpreter;
import com.zfoo.storage.model.IStorage;
import com.zfoo.storage.model.IdDef;
Expand Down Expand Up @@ -194,24 +195,22 @@ private <INDEX> String getMethodToField(Func1<V, INDEX> func) {
// 4. 通过将func带入到dataMap中求解,适合GraalVM环境中
if (indexName == null) {
try {
var fields = clazz.getDeclaredFields();
Arrays.stream(fields).forEach(ReflectionUtils::makeAccessible);
var fields = Arrays.stream(clazz.getDeclaredFields())
.filter(it -> it.isAnnotationPresent(Index.class))
.peek(ReflectionUtils::makeAccessible)
.toList();

for (var value : getAll()) {
var r = func.apply(value);
// 如果只有一个能匹配到func的返回值则就是这个方法
var count = 0;
var fieldName = StringUtils.EMPTY;
if (r == null) {
continue;
}
for (var field : fields) {
var fieldValue = ReflectionUtils.getField(field, value);
if (Objects.equals(r, fieldValue)) {
count++;
fieldName = field.getName();
if (Objects.equals(r, fieldValue) && r.getClass() == fieldValue.getClass()) {
indexName = field.getName();
}
}
if (count == 1) {
indexName = fieldName;
break;
}
}
} catch (Exception e) {
}
Expand Down

0 comments on commit b64a7a4

Please sign in to comment.