All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.fieldintercept.CompositeFieldIntercept Maven / Gradle / Ivy

The newest version!
package com.github.fieldintercept;

import com.github.fieldintercept.util.TypeUtil;

import java.util.Arrays;
import java.util.List;

/**
 * 组合字段字段设置名称
 * 例子:
 * 
 *
 *     public abstract class AbstractService,
 *         PO extends AbstractPO,
 *         ID extends Number> implements CompositeFieldIntercept {
 *
 *          private final Class keyClass = CompositeFieldIntercept.getKeyClass(this, AbstractService.class, "ID", Integer.class);
 *
 *          private final Class valueClass = CompositeFieldIntercept.getValueClass(this, AbstractService.class, "PO", Object.class);
 *
 *          private final KeyNameFieldIntercept keyNameFieldIntercept = new KeyNameFieldIntercept<>(keyClass, this::selectNameMapByKeys, 0);
 *
 *          private final KeyValueFieldIntercept keyValueFieldIntercept = new KeyValueFieldIntercept<>(keyClass, valueClass, this::selectValueMapByKeys, 0);
 *
 *          \@Override
 *          public KeyNameFieldIntercept keyNameFieldIntercept() {
 *              return keyNameFieldIntercept;
 *          }
 *
 *          \@Override
 *          public KeyValueFieldIntercept keyValueFieldIntercept() {
 *              return keyValueFieldIntercept;
 *          }
 *     }
 * 
* * @author acer01 */ public interface CompositeFieldIntercept extends ReturnFieldDispatchAop.FieldIntercept, ReturnFieldDispatchAop.SelectMethodHolder { static > Class getKeyClass(INSTANCE thisInstance, Class interceptClass, String genericTypeParamName, Class defaultClass) { Class keyClass = null; if (thisInstance.getClass() != interceptClass) { try { Class key = TypeUtil.findGenericType(thisInstance, interceptClass, genericTypeParamName); keyClass = (Class) key; } catch (IllegalStateException ignored) { } } if (keyClass == null) { keyClass = (Class) defaultClass; } return keyClass; } static > Class getValueClass(INSTANCE thisInstance, Class interceptClass, String genericTypeParamName, Class defaultClass) { Class genericType; try { genericType = (Class) TypeUtil.findGenericType(thisInstance, interceptClass, genericTypeParamName); } catch (IllegalStateException ignored) { genericType = null; } if (genericType == null) { genericType = (Class) defaultClass; } return genericType; } KeyNameFieldIntercept keyNameFieldIntercept(); KeyValueFieldIntercept keyValueFieldIntercept(); @Override default void accept(JOIN_POINT joinPoint, List fieldList) { ReturnFieldDispatchAop.SplitCFieldList split = ReturnFieldDispatchAop.split(fieldList); List keyNameFieldList = split.getKeyNameFieldList(); List keyValueFieldList = split.getKeyValueFieldList(); ReturnFieldDispatchAop aop; if (keyNameFieldList != null && keyValueFieldList != null && (aop = ReturnFieldDispatchAop.getAop(fieldList)) != null) { List runnableList; if (keyValueFieldList.size() > keyNameFieldList.size()) { runnableList = Arrays.asList( () -> keyValueFieldIntercept().accept(joinPoint, keyValueFieldList), () -> keyNameFieldIntercept().accept(joinPoint, keyNameFieldList) ); } else { runnableList = Arrays.asList( () -> keyNameFieldIntercept().accept(joinPoint, keyNameFieldList), () -> keyValueFieldIntercept().accept(joinPoint, keyValueFieldList) ); } // await aop.await(runnableList); } else { if (keyNameFieldList != null) { keyNameFieldIntercept().accept(joinPoint, keyNameFieldList); } if (keyValueFieldList != null) { keyValueFieldIntercept().accept(joinPoint, keyValueFieldList); } } } @Override default void begin(String beanName, ReturnFieldDispatchAop.GroupCollect collect, List fieldList) { ReturnFieldDispatchAop.SplitCFieldList split = ReturnFieldDispatchAop.split(fieldList); List keyNameFieldList = split.getKeyNameFieldList(); List keyValueFieldList = split.getKeyValueFieldList(); if (keyNameFieldList != null) { keyNameFieldIntercept().begin(beanName, collect, keyNameFieldList); } if (keyValueFieldList != null) { keyValueFieldIntercept().begin(beanName, collect, keyValueFieldList); } } @Override default void end(String beanName, ReturnFieldDispatchAop.GroupCollect collect, List fieldList) { ReturnFieldDispatchAop.SplitCFieldList split = ReturnFieldDispatchAop.split(fieldList); List keyNameFieldList = split.getKeyNameFieldList(); List keyValueFieldList = split.getKeyValueFieldList(); if (keyNameFieldList != null) { keyNameFieldIntercept().end(beanName, collect, keyNameFieldList); } if (keyValueFieldList != null) { keyValueFieldIntercept().end(beanName, collect, keyValueFieldList); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy