Spring框架之基础类—BeanMetadataAttribute实现类(转载)

原文出处:https://blog.csdn.net/jiabaoyu19lindaiyu/article/details/78404156

一、BeanMetadataAttribute简介

Bean元数据定义中以键-值风格的属性信息。实现BeanMetadataElement接口(定义Bean元数据的顶层接口)。

二、BeanMetadataAttribute源码详解

public class BeanMetadataAttribute implements BeanMetadataElement {
    /**
     * 属性信息
     */
    private final String name;      // 属性名
    private final Object value;     // 属性值
    private Object source;      // 属性所属对象


    /**
     * 构造器(设置属性信息)
     */
    public BeanMetadataAttribute(String name, Object value) {
        Assert.notNull(name, "Name must not be null");
        this.name = name;
        this.value = value;
    }

    /**
     * 获取属性名、属性值以及获取、设置属性所属对象
     */
    public String getName() {
        return this.name;
    }
    public Object getValue() {
        return this.value;
    }
    public void setSource(Object source) {
        this.source = source;
    }
    @Override
    public Object getSource() {
        return this.source;
    }

    /**
     * 判断属性是否相等
     */
    @Override
    public boolean equals(Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof BeanMetadataAttribute)) {
            return false;
        }
        BeanMetadataAttribute otherMa = (BeanMetadataAttribute) other;
        return (this.name.equals(otherMa.name) &&
                ObjectUtils.nullSafeEquals(this.value, otherMa.value) &&
                ObjectUtils.nullSafeEquals(this.source, otherMa.source));
    }

    @Override
    public int hashCode() {
        return this.name.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.value);
    }

    @Override
    public String toString() {
        return "metadata attribute '" + this.name + "'";
    }
}
posted @ 2018-07-11 22:21  青青子衿J  阅读(1168)  评论(0)    收藏  举报