循环遍历取值

@Data
public class TagV2MatchContext {

    private TagV2MatchInfo matchInfo;

    private TagV2InterfaceInfo interfaceInfo;

    private TagV2ReturnValue returnValue;

    private UserRequestContext userRequestContext;


    public static TagV2MatchContext from(RealtimeTagValue realtimeTagValue, RealtimeTagInfo realtimeTagInfo, UserRequestContext requestContext) {
        TagV2InterfaceInfo interfaceInfo = TagV2InterfaceInfo.form(realtimeTagInfo);
        TagV2MatchInfo matchInfo = TagV2MatchInfo.from(realtimeTagValue);

        TagV2MatchContext context = new TagV2MatchContext();
        context.setInterfaceInfo(interfaceInfo);
        context.setMatchInfo(matchInfo);
        context.setUserRequestContext(requestContext);
        return context;
    }
}


TagV2MatchContext(matchInfo=TagV2MatchInfo(category=addNumbers, tagValue=5,7,9,15,21, extValue={"matchType":"4","vipRuleOptionValue":""}, matchType=4, hasRuleOption=false, ruleOption=null), interfaceInfo=TagV2InterfaceInfo(tagName=addNumbers, tagZhName=整型数组, interfaceProvider=, interfaceExtInfo={"signStrategy":"","timeout":"100"}, interfaceProtocol=INTERNAL, interfaceAddress=UserRequestContext.bizParamMap.addNumbers, interfaceType=NUMBER[]), returnValue=null, userRequestContext=UserRequestContext(userId=2087321718, deviceId=868610049930933, rewriteDeviceIdAlready=false, deviceInfo=null, brand=null, myOppoAppVersion=700, country=null, push=false, isClientSupportSigning=false, phoneModel=PDEM30, categoryInternalMap={"addNumbers":[5,15]}, bizParamMap={"addNumbers":[5,15]}, getBrandFromOnlineDeviceIfAbsent=true, getDeviceIdFromOnlineDeviceIfAbsent=true, sourcePackage=null, requestScopeObjectHolder=RequestScopeObjectHolder{}, requestSource=null, osVersion=null, payInfo=null, themeVouContext=null, version=null, transactionId=null, udid=null, vaid=null, aaid=null, oaid=null, userGroupId=5001040, hardwareType=null))

interfaceAddress=UserRequestContext.bizParamMap.addNumbers



  public static final ConcurrentHashMap<Class<?>, BeanResolver> RESOLVER_MAP = new ConcurrentHashMap<>();

    private Object getValue(TagV2MatchContext matchContext, String interfaceAddress) {
        Iterator<String> propChain = Arrays.stream(interfaceAddress.split("[.]")).iterator();
        if (!propChain.hasNext()) {
            throw new IllegalArgumentException("配置错误,interfaceAddress 格式错误");
        }

        Object root;
        String rootName = propChain.next();
        if (REQUEST_CONTEXT.equalsIgnoreCase(rootName)) {
            root = RequestContextManager.get();
        } else if (USER_REQUEST_CONTEXT.equalsIgnoreCase(rootName)) {
            root = matchContext.getUserRequestContext();
        } else {
            throw new IllegalArgumentException("配置错误,interfaceAddress 不支持此配置 " + rootName);
        }

        log.debug("interfaceAddress:{} root:{} ", interfaceAddress, root);

        return getValue(root, propChain);
    }

    private Object getValue(Object object, Iterator<String> propChain) {
        BeanResolver beanResolver;
        while (propChain.hasNext() && object != null) {
            String propName = propChain.next();
            beanResolver = RESOLVER_MAP.computeIfAbsent(object.getClass(), BeanResolver::newInstance);
            object = beanResolver.get(object, propName);
        }
        return object;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值