码迷,mamicode.com
首页 > 其他好文 > 详细

MyBatis PropertyTokenizer

时间:2019-12-22 16:51:33      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:util   ide   imp   prope   use   null   next   iter   over   

PropertyTokenizer

package org.apache.ibatis.reflection.property;
import java.util.Iterator;
/*
    例1: 参数: user[1].linkman.name
        children=linkman.name
        indexedName=user[1]
        name=user
        index=1
    例2: 参数: user
        children=null
        indexedName=user
        name=user
        index=null
    hasNext()判断是否有子属性,next()获取子属性。
*/
public class PropertyTokenizer implements Iterator<PropertyTokenizer> {
  private String name; //名称
  private final String indexedName; //带索引的名称
  private String index; //索引
  private final String children; //子名称

  public PropertyTokenizer(String fullname) {
    int delim = fullname.indexOf('.');
    if (delim > -1) {
      name = fullname.substring(0, delim);
      children = fullname.substring(delim + 1);
    } else {
      name = fullname;
      children = null;
    }
    indexedName = name;
    delim = name.indexOf('[');
    if (delim > -1) {
      index = name.substring(delim + 1, name.length() - 1);
      name = name.substring(0, delim);
    }
  }


  @Override
  public boolean hasNext() {
    return children != null;
  }

  @Override
  public PropertyTokenizer next() {
    return new PropertyTokenizer(children);
  }

}

MyBatis PropertyTokenizer

标签:util   ide   imp   prope   use   null   next   iter   over   

原文地址:https://www.cnblogs.com/mozq/p/12079726.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!