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 43f2e60 commit a590553
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 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 @@ -19,7 +19,10 @@
import com.zfoo.storage.model.IdDef;
import com.zfoo.storage.model.IndexDef;
import com.zfoo.storage.util.function.Func1;
import com.zfoo.storage.util.lambda.*;
import com.zfoo.storage.util.lambda.IdeaProxyLambdaMeta;
import com.zfoo.storage.util.lambda.ReflectLambdaMeta;
import com.zfoo.storage.util.lambda.SerializedLambda;
import com.zfoo.storage.util.lambda.ShadowLambdaMeta;
import org.springframework.lang.Nullable;
import org.springframework.util.ConcurrentReferenceHashMap;

Expand Down Expand Up @@ -195,19 +198,18 @@ private <INDEX> String getMethodToField(Func1<V, INDEX> func) {
Arrays.stream(fields).forEach(ReflectionUtils::makeAccessible);
for (var value : getAll()) {
var r = func.apply(value);
var valueFields = Arrays.stream(fields)
.map(it -> ReflectionUtils.getField(it, value))
.filter(it -> it.equals(r) && it.getClass() == r.getClass())
.toList();
// 如果只有一个能匹配到func的返回值则就是这个方法
if (valueFields.size() == 1) {
for (var field : fields) {
if (!ReflectionUtils.getField(field, value).equals(r)) {
continue;
}
indexName = field.getName();
break;
var count = 0;
var fieldName = StringUtils.EMPTY;
for (var field : fields) {
var fieldValue = ReflectionUtils.getField(field, value);
if (Objects.equals(r, fieldValue)) {
count++;
fieldName = field.getName();
}
}
if (count == 1) {
indexName = fieldName;
break;
}
}
Expand Down

0 comments on commit a590553

Please sign in to comment.