/** * Compares this factory with the specified object for equality. * The default implementation returns {@code true} if and only if: * <p> * <ul> * <li>Both objects are of the exact same class * (a <cite>is instance of</cite> relationship is not enough).</li> * <li>{@linkplain #getImplementationHints implementation hints} are * {@linkplain Map#equals equal}.</li> * </ul> * <p> * The requirement for the <cite>exact same class</cite> is needed for consistency with the * {@linkplain FactoryRegistry factory registry} working, since at most one instance of a given * class {@linkplain FactoryRegistry#getServiceProviderByClass) is allowed} in a registry. * * @since 2.3 */ public final boolean equals(final Object object) { if (object == this) { return true; } if (object!=null && object.getClass().equals(getClass())) { final AbstractFactory that = (AbstractFactory) object; return this.priority == that.priority && new FactoryComparator(this, that).compare(new HashSet()); } return false; }
if (this.priority == that.priority) { final Set<FactoryComparator> comparators = new HashSet<FactoryComparator>(); return new FactoryComparator(this, that).compare(comparators);
/** * Returns {@code true} if {@code f1} and {@code f2} are equals. * * @param done An initially empty set. Used internally for preventing infinite recursivity. */ boolean compare(final Set<FactoryComparator> done) { if (done.add(this)) { final Map<RenderingHints.Key, ?> m1 = f1.getImplementationHints(); final Map<RenderingHints.Key, ?> m2 = f2.getImplementationHints(); if (m1.size() != m2.size()) { return false; } for (final Map.Entry<RenderingHints.Key, ?> entry : m1.entrySet()) { final Object key = entry.getKey(); final Object v1 = entry.getValue(); final Object v2 = m2.get(key); if (v1 == v2) continue; if (v1 instanceof Factory) { if (v2 == null || !v1.getClass().equals(v2.getClass()) || !new FactoryComparator((Factory) v1, (Factory) v2).compare(done)) { return false; } } else if (!Utilities.equals(v1, v2)) { return false; } } } return true; }
if (v1 instanceof Factory) { if (v2 == null || !v1.getClass().equals(v2.getClass()) || !new FactoryComparator((Factory) v1, (Factory) v2).compare(done))