Module bus.core

Class BeanPath<T>

java.lang.Object
org.miaixz.bus.core.bean.path.BeanPath<T>
All Implemented Interfaces:
Iterator<BeanPath<T>>

public class BeanPath<T> extends Object implements Iterator<BeanPath<T>>
Bean路径表达式,用于获取多层嵌套Bean中的字段值或Bean对象 根据给定的表达式,查找Bean中对应的属性值对象。 表达式分为两种:
  1. .表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值
  2. []表达式,可以获取集合等对象中对应index的值
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • BeanPath

      public BeanPath(String expression, NodeBeanFactory<T> beanFactory)
      构造
      Parameters:
      expression - 表达式
      beanFactory - NodeBean工厂,用于Bean的值创建、获取和设置
  • Method Details

    • of

      public static BeanPath<Object> of(String expression)
      创建Bean路径
      Parameters:
      expression - 表达式
      Returns:
      BeanPath
    • of

      public static <T> BeanPath<T> of(String expression, NodeBeanFactory<T> beanFactory)
      创建Bean路径
      Type Parameters:
      T - Bean类型
      Parameters:
      expression - 表达式
      beanFactory - NodeBean工厂,用于Bean的值创建、获取和设置
      Returns:
      BeanPath
    • getNode

      public Node getNode()
      获取节点
      Returns:
      节点
    • getChild

      public String getChild()
      获取子表达式
      Returns:
      子表达式
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
    • next

      public BeanPath<T> next()
      Specified by:
      next in interface Iterator<T>
    • getValue

      public Object getValue(T bean)
      获取路径对应的值
      Parameters:
      bean - Bean对象
      Returns:
      路径对应的值
    • setValue

      public Object setValue(T bean, Object value)
      设置路径对应的值,如果路径节点为空,自动创建之
      Parameters:
      bean - Bean对象
      value - 设置的值
      Returns:
      bean 如果在原Bean对象基础上设置值,返回原Bean,否则返回新的Bean
    • toString

      public String toString()
      Overrides:
      toString in class Object