@Override public boolean equals(Object obj) { return ObjectContracts.equals(this, obj, KEY_FIELDS); }
@Override public boolean equals(Object obj) { return ObjectContracts.equals(this, obj, KEY_PROPERTIES); }
@Override public boolean equals(Object obj) { return ObjectContracts.equals(this, obj, KEY_PROPERTIES); } }
@Override public boolean equals(Object obj) { return ObjectContracts.equals(this, obj, KEY_PROPERTIES); }
/** * Returns whether two objects are equal, considering just the specified property name(s). * @deprecated - please be aware that this utility heavily uses reflection. We don't actually intend to deprecate this method (it's useful while prototyping), but we wanted to bring this to your attention! * @param propertyNames - the property name or names, CSV format. If multiple properties, use the {@link #equals(Object, Object, String...)} varargs} overloaded version of this method. */ @Deprecated public static boolean equals(Object p, Object q, String propertyNames) { if(p==null && q==null) { return true; } if(p==null || q==null) { return false; } if(p.getClass() != q.getClass()) { return false; } final Iterable<String> propertyNamesIter = csvToIterable(propertyNames); return equals(p, q, propertyNamesIter); }
/** * Returns whether two objects are equal, considering just the specified property name(s). * @deprecated - please be aware that this utility heavily uses reflection. We don't actually intend to deprecate this method (it's useful while prototyping), but we wanted to bring this to your attention! */ @Deprecated public static boolean equals(Object p, Object q, String... propertyNames) { if(p==null && q==null) { return true; } if(p==null || q==null) { return false; } if(p.getClass() != q.getClass()) { return false; } final Iterable<String> propertyNamesIter = varargsToIterable(propertyNames); return equals(p, q, propertyNamesIter); }
@Test public void nullsAreEqual() throws Exception { assertTrue(ObjectContracts.equals(null, null, "number")); }
@Test public void happyCase() throws Exception { assertTrue(ObjectContracts.equals(p, q, "number")); }
@Test public void notEqualDifferentValues() throws Exception { assertFalse(ObjectContracts.equals(p, r, "number")); }
@Test public void notEqualDifferentTypes() throws Exception { assertFalse(ObjectContracts.equals(p, x, "number")); }
@Test public void notEqualNull() throws Exception { assertFalse(ObjectContracts.equals(p, null, "number")); }