/** * Create a <i>hashCode</i> and <i>equals</i> implementation for the given class and fields. Callers must verify that * the types of the fields override the default identity based equals and hashcode implementations. No warnings are * issued in an event where the field type uses the implementation of java.lang.Object. * * This method ignores static fields for generating the equals and hashCode methods, since they are ideally not meant * to be used in these cases. Although transient fields could also be ignored, they are not since there is no * mechanism to convey warnings (not errors) in this case. * * @param clazz class to be changed * @param fields fields to be used in the equals/hashCode methods */ public static void createHashCodeAndEquals(final JavaClassSource clazz, final FieldSource<?>... fields) { createEquals(clazz, fields); createHashCode(clazz, fields); }
/** * Create a <i>hashCode</i> and <i>equals</i> implementation for the given class and fields. Callers must verify that * the types of the fields override the default identity based equals and hashcode implementations. No warnings are * issued in an event where the field type uses the implementation of java.lang.Object. * * This method ignores static fields for generating the equals and hashCode methods, since they are ideally not meant * to be used in these cases. Although transient fields could also be ignored, they are not since there is no * mechanism to convey warnings (not errors) in this case. * * @param clazz class to be changed * @param fields fields to be used in the equals/hashCode methods */ public static void createHashCodeAndEquals(final JavaClassSource clazz, final FieldSource<?>... fields) { createEquals(clazz, fields); createHashCode(clazz, fields); }
Refactory.createHashCode(targetClass, selectedFields.toArray(new FieldSource<?>[selectedFields.size()])); Refactory.createHashCode(targetClass, selectedFields.toArray(new FieldSource<?>[selectedFields.size()]));
Refactory.createHashCode(javaSource, javaSource.getField("id")); Refactory.createHashCode(javaSource, javaSource.getFields().toArray(new FieldSource[javaSource.getFields().size()]));