/** * 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. * * @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(Object lhs, Object rhs) { Set<Pair<IDKey, IDKey>> registry = getRegistry(); Pair<IDKey, IDKey> pair = getRegisterPair(lhs, rhs); Pair<IDKey, IDKey> swappedPair = Pair.of(pair.getLeft(), pair.getRight()); return registry != null && (registry.contains(pair) || registry.contains(swappedPair)); }
/** * Converters value pair into a register pair. * * @param lhs <code>this</code> object * @param rhs the other object * @return the pair */ static Pair<IDKey, IDKey> getRegisterPair(Object lhs, Object rhs) { IDKey left = new IDKey(lhs); IDKey right = new IDKey(rhs); return Pair.of(left, right); }