java - org.apache.commons.lang3.builder.EqualsBuilder

查看:102
本文介绍了java - org.apache.commons.lang3.builder.EqualsBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

static Set<Pair<IDKey, IDKey>> getRegistry() {
    return REGISTRY.get();
}

static Pair<IDKey, IDKey> getRegisterPair(final Object lhs, final Object rhs) {
    final IDKey left = new IDKey(lhs);
    final IDKey right = new IDKey(rhs);
    return Pair.of(left, right);
}

/**
 * <p>
 * Returns <code>true</code> if the registry contains the given object pair.
 * Used by the reflection methods to avoid infinite loops.
 * Objects might be swapped therefore a check is needed if the object pair
 * is registered in given or swapped order.
 * </p>
 *
 * @param lhs <code>this</code> object to lookup in registry
 * @param rhs the other object to lookup on registry
 * @return boolean <code>true</code> if the registry contains the given object.
 * @since 3.0
 */
static boolean isRegistered(final Object lhs, final Object rhs) {
    final Set<Pair<IDKey, IDKey>> registry = getRegistry();
    final Pair<IDKey, IDKey> pair = getRegisterPair(lhs, rhs);
    final Pair<IDKey, IDKey> swappedPair = Pair.of(pair.getLeft(), pair.getRight());

    return registry != null
            && (registry.contains(pair) || registry.contains(swappedPair));
}

上面是 org.apache.commons.lang3.builder.EqualsBuilder 的源码。 注释说对象注册的时候顺序可能发生交换,所以要检测交换顺序后的 Pair,但是 pairswappedPair 中对象的顺序并没有交换呀。那有什么意义呢?还是源码错了?

解决方案

stackoverflow 上问了下,这是一个 bugGitHub repository 已经接受了 pr, 下个版本就解决了。

这篇关于java - org.apache.commons.lang3.builder.EqualsBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆