Pop quiz, hot shot. There are seven different true/false flags. You have only a single integer to represent them. What do you do? What do you do?

When Stephan E's predecessor was faced with this problem, he knew exactly how to handle things. He used the integer to store a bit pattern. Of sorts. Well... kinda...

public class BestMatchedEntity { public static final int MATCH_EMAIL_ONLY = 0001000; public static final int MATCH_LNAME_ONLY = 1000000; public static final int MATCH_LNAME_DOB = 1100000; public static final int MATCH_LNAME_DOB_EMAIL = 1101000; public static final int MATCH_LNAME_DOB_FNAME = 1110000; public static final int MATCH_LNAME_DOB_FNAME_ADDR = 1110001; public static final int MATCH_LNAME_DOB_FNAME_TELNO = 1110010; public static final int MATCH_LNAME_DOB_FNAME_TELNO_ADDR = 1110011; public static final int MATCH_LNAME_DOB_FNAME_REFNO = 1110100; public static final int MATCH_LNAME_DOB_FNAME_REFNO_ADDR = 1110101; public static final int MATCH_LNAME_DOB_FNAME_REFNO_TELNO = 1110110; public static final int MATCH_LNAME_DOB_FNAME_REFNO_TELNO_ADDR = 1110111; public static final int MATCH_LNAME_DOB_FNAME_EMAIL = 1111000; public static final int MATCH_LNAME_DOB_FNAME_EMAIL_ADDR = 1111001; public static final int MATCH_LNAME_DOB_FNAME_EMAIL_TELNO = 1111010; public static final int MATCH_LNAME_DOB_FNAME_EMAIL_TELNO_ADDR = 1111011; public static final int MATCH_LNAME_DOB_FNAME_EMAIL_REFNO = 1111100; public static final int MATCH_LNAME_DOB_FNAME_EMAIL_REFNO_ADDR = 1111101; public static final int MATCH_LNAME_DOB_FNAME_EMAIL_REFNO_TELNO = 1111110; public static final int MATCH_LNAME_DOB_FNAME_EMAIL_REFNO_TELNO_ADDR = 1111111; public static final int NUM_OF_MATCH_FIELDS = 7; ... }

And how exactly did this bit pattern get used? Well...

if (hasLastName && hasDob && hasFirstName && hasEmail && hasRefNo && hasTelNo && hasAddr) { matchPattern = MATCH_LNAME_DOB_FNAME_EMAIL_REFNO_TELNO_ADDR; } else if (hasLastName && hasDob && hasFirstName && hasEmail && hasRefNo && hasTelNo && !hasAddr) { matchPattern = MATCH_LNAME_DOB_FNAME_EMAIL_REFNO_TELNO; } else if (hasLastName && hasDob && hasFirstName && hasEmail && hasRefNo && !hasTelNo && hasAddr) { matchPattern = MATCH_LNAME_DOB_FNAME_EMAIL_REFNO_ADDR; (hasLastName && hasDob && hasFirstName && hasEmail && hasRefNo && !hasTelNo && !hasAddr) { matchPattern = MATCH_LNAME_DOB_FNAME_EMAIL_REFNO; ...