From 40bceecbdd98308cd1c71db8792e1d1d15d5b22c Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 10 Aug 2015 15:37:05 +0200 Subject: [PATCH] =?utf8?q?Reverted=20a=20bit=20back=20because=20the=20Cons?= =?utf8?q?oleClient=20has=20enterChar()=20which=20requires=20an=20array=20?= =?utf8?q?of=20chars=20+=20renamed=20+=20changed=20type=20of=20attribute?= =?utf8?q?=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/org/mxchange/jcore/contact/Gender.java | 111 ++++++++++++++++++++- 1 file changed, 106 insertions(+), 5 deletions(-) diff --git a/src/org/mxchange/jcore/contact/Gender.java b/src/org/mxchange/jcore/contact/Gender.java index 598b697..e28734c 100644 --- a/src/org/mxchange/jcore/contact/Gender.java +++ b/src/org/mxchange/jcore/contact/Gender.java @@ -28,19 +28,108 @@ public enum Gender { /** * Unknown enum */ - UNKNOWN("BaseContact.gender.unknown.text"), + UNKNOWN('U', "BaseContact.gender.unknown.text"), /** * Male enum */ - MALE("BaseContact.gender.male.text"), + MALE('M', "BaseContact.gender.male.text"), /** * Female enum */ - FEMALE("BaseContact.gender.female.text"), + FEMALE('F', "BaseContact.gender.female.text"), /** * Company enum */ - COMPANY("BaseContact.gender.company.text"); + COMPANY('C', "BaseContact.gender.company.text"); + + /** + * Cache for valid chars + */ + private static char[] validChars; + + /** + * Getter for Gender enum from given character + * + * @param gender Gender character + * @return Gender enum + */ + public static Gender fromChar (final char gender) { + Gender g = null; + switch (gender) { + case 'U': // Unknown + g = UNKNOWN; + break; + + case 'M': // Male + g = MALE; + break; + + case 'F': // Female + g = FEMALE; + break; + + case 'C': // Company + g = COMPANY; + break; + + default: // Unsupported + throw new IllegalArgumentException("gender " + gender + " is invalid."); + } + + // Return it + //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName()); + return g; + } + + /** + * Valid chars + * + * @return Valid chars + */ + public static char[] validChars () { + // Is cache set? + if (validChars != null) { + // Return it + return validChars; + } + + // Init array + char[] valid = new char[3]; + + // Get values + int i = 0; + for (Object value : values()) { + // First cast + Gender gender = (Gender) value; + + // Debug message + //* NOISY-DEBUG: */ System.out.println("gender=" + gender); + // Is it UNKNOWN? + if (gender.equals(Gender.UNKNOWN)) { + // Skip this + continue; + } + + // Debug message + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i)); + // Get database value as this is also the access + valid[i] = gender.getAccessChar(); + + // Increment index + i++; + } + + // Set it here + validChars = valid; + + // Return finialized array + return valid; + } + + /** + * Value being entered by ConsoleClient + */ + private final char accessChar; /** * Output value (for messages) @@ -50,12 +139,24 @@ public enum Gender { /** * Constructor * + * @param accessChar Value being entered by ConsoleClient * @param messageKey Message key for resource file */ - private Gender (final String messageKey) { + private Gender (final char accessChar, final String messageKey) { + // Set both + this.accessChar = accessChar; this.messageKey = messageKey; } + /** + * Database value + * + * @return the accessChar + */ + public char getAccessChar () { + return this.accessChar; + } + /** * Output value (for messages) * -- 2.39.5