Skip to content

Commit

Permalink
优化BindAnnotationGroup.java中部分写法;
Browse files Browse the repository at this point in the history
  • Loading branch information
ZZemptypoint committed Dec 18, 2021
1 parent dac891f commit 270a2d1
Showing 1 changed file with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.diboot.core.binding.parser;

import com.diboot.core.binding.annotation.*;
import com.diboot.core.util.V;
import lombok.extern.slf4j.Slf4j;

import java.lang.annotation.Annotation;
Expand All @@ -30,6 +31,7 @@
* @version 2.0<br>
* @date 2019/04/03 <br>
*/
@SuppressWarnings("JavaDoc")
@Slf4j
public class BindAnnotationGroup {
/**
Expand Down Expand Up @@ -71,20 +73,19 @@ public class BindAnnotationGroup {
* @param annotation
*/
public void addBindAnnotation(String fieldName, Class<?> fieldClass, Annotation annotation){
FieldAnnotation fieldAnnotation = new FieldAnnotation(fieldName, fieldClass, annotation);
if(annotation instanceof BindDict){
if(bindDictAnnotations == null){
bindDictAnnotations = new ArrayList<>(4);
}
bindDictAnnotations.add(new FieldAnnotation(fieldName, fieldClass, annotation));
if(requireSequential == false && bindFieldGroupMap != null){
bindFieldGroupMap.values().forEach(list -> {
list.forEach(item -> {
if(item.getFieldName().equals(fieldName) && item.getFieldClass().getName().equals(fieldClass.getName())){
requireSequential = true;
return;
}
});
});
bindDictAnnotations.add(fieldAnnotation);
if(!requireSequential && bindFieldGroupMap != null){
// 是否存在重复的字段
// 只要任意一个符合条件,即可结束遍历
requireSequential = bindFieldGroupMap.values().stream().anyMatch(list ->
list.stream().anyMatch(item ->
item.getFieldName().equals(fieldName) && item.getFieldClass().equals(fieldClass)
));
}
return;
}
Expand Down Expand Up @@ -112,40 +113,36 @@ public void addBindAnnotation(String fieldName, Class<?> fieldClass, Annotation
bindFieldGroupMap = new HashMap<>(4);
}
List<FieldAnnotation> list = bindFieldGroupMap.computeIfAbsent(key, k -> new ArrayList<>(4));
list.add(new FieldAnnotation(fieldName, fieldClass, annotation));
if(requireSequential == false && bindDictAnnotations != null){
bindDictAnnotations.forEach(item -> {
if(item.getFieldName().equals(fieldName) && item.getFieldClass().getName().equals(fieldClass.getName())){
requireSequential = true;
return;
}
});
list.add(fieldAnnotation);
if(!requireSequential && bindDictAnnotations != null){
// 是否存在重复的字段
requireSequential = bindDictAnnotations.stream().anyMatch(item ->
item.getFieldName().equals(fieldName) && item.getFieldClass().equals(fieldClass)
);
}
}
else if(annotation instanceof BindEntity){
if(bindEntityAnnotations == null){
bindEntityAnnotations = new ArrayList<>(4);
}
FieldAnnotation fieldAnno = new FieldAnnotation(fieldName, fieldClass, annotation);
bindEntityAnnotations.add(fieldAnno);
bindEntityAnnotations.add(fieldAnnotation);
if(((BindEntity)annotation).deepBind()){
if(deepBindEntityAnnotations == null){
deepBindEntityAnnotations = new ArrayList<>(4);
}
deepBindEntityAnnotations.add(fieldAnno);
deepBindEntityAnnotations.add(fieldAnnotation);
}
}
else if(annotation instanceof BindEntityList){
if(bindEntityListAnnotations == null){
bindEntityListAnnotations = new ArrayList<>(4);
}
FieldAnnotation fieldAnno = new FieldAnnotation(fieldName, fieldClass, annotation);
bindEntityListAnnotations.add(fieldAnno);
bindEntityListAnnotations.add(fieldAnnotation);
if(((BindEntityList)annotation).deepBind()){
if(deepBindEntityListAnnotations == null){
deepBindEntityListAnnotations = new ArrayList<>(4);
}
deepBindEntityListAnnotations.add(fieldAnno);
deepBindEntityListAnnotations.add(fieldAnnotation);
}
}
else if(annotation instanceof BindFieldList){
Expand All @@ -154,7 +151,7 @@ else if(annotation instanceof BindFieldList){
bindFieldListGroupMap = new HashMap<>(4);
}
List<FieldAnnotation> list = bindFieldListGroupMap.computeIfAbsent(key, k -> new ArrayList<>(4));
list.add(new FieldAnnotation(fieldName, fieldClass, annotation));
list.add(fieldAnnotation);
}
}

Expand Down Expand Up @@ -187,8 +184,7 @@ public List<FieldAnnotation> getDeepBindEntityListAnnotations() {
}

public boolean isEmpty() {
return bindDictAnnotations == null && bindFieldGroupMap == null && bindEntityAnnotations == null
&& bindEntityListAnnotations == null && bindFieldListGroupMap == null;
return V.isAllEmpty(bindDictAnnotations, bindFieldGroupMap, bindEntityAnnotations, bindEntityListAnnotations, bindFieldListGroupMap);
}

/**
Expand Down

0 comments on commit 270a2d1

Please sign in to comment.