1 package org.pojomatic.annotations; 2 3 import java.util.Collections; 4 import java.util.EnumSet; 5 import java.util.Set;import java.util.Arrays; 6 7 import org.pojomatic.Pojomatic; 8 import org.pojomatic.internal.PropertyRole; 9 10 /** 11 * A policy for defining which sets of {@link Pojomatic} operations 12 * ({@code equals}, {@code hashCode} and {@code toString}) should use all properties by default. 13 * This is set class-wide using {@link AutoProperty}. 14 * @see PojomaticPolicy 15 */ 16 public enum DefaultPojomaticPolicy { 17 18 /** 19 * Use all properties for both {@code hashCode} and {@code equals} by default. 20 * Anything included in {@code public int hashCode()} should also be included in 21 * {@code public boolean equals(Object)} to preserve the general 22 * contract of {@link Object#hashCode()}. 23 * 24 * @see Object#hashCode() 25 * @see Object#equals(Object) 26 */ 27 HASHCODE_EQUALS(PropertyRole.HASH_CODE, PropertyRole.EQUALS), 28 29 /** 30 * Use all properties for {@code equals} only by default. 31 * 32 * @see Object#equals(Object) 33 */ 34 EQUALS(PropertyRole.EQUALS), 35 36 /** 37 * Use all properties for both {@code equals} and {@code toString} by default. 38 * 39 * @see Object#equals(Object) 40 * @see Object#toString() 41 */ 42 EQUALS_TO_STRING(PropertyRole.EQUALS, PropertyRole.TO_STRING), 43 44 /** 45 * Use all properties for both {@code toString} only by default. 46 * 47 * @see Object#toString() 48 */ 49 TO_STRING(PropertyRole.TO_STRING), 50 51 /** 52 * Use all properties for {@code hashCode}, {@code equals} and {@code toString} by default. 53 */ 54 ALL(PropertyRole.EQUALS, PropertyRole.HASH_CODE, PropertyRole.TO_STRING), 55 56 /** 57 * Do not use any properties for any of {@code hashCode}, {@code equals} or {@code toString} 58 * by default. 59 */ 60 NONE(); 61 62 /** 63 * @return the roles this specified by this policy. 64 */ 65 public Set<PropertyRole> getRoles() { 66 return roles; 67 } 68 69 private DefaultPojomaticPolicy(PropertyRole... roles) { 70 Set<PropertyRole> roleSet = EnumSet.noneOf(PropertyRole.class); 71 roleSet.addAll(Arrays.asList(roles)); 72 this.roles = Collections.unmodifiableSet(roleSet); 73 } 74 75 private final Set<PropertyRole> roles; 76 }