Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to get the enum itself first by using
RegoDocumentType.getByValue(createOrderRequest.getIdDocument().getIdType())

Then check for null value, if it is not null, it will return the enum value. Else, it will return the
createOrderRequest.getIdDocument().getIdType()
as default.

So how do I code to only use one if statement to cater for both NRIC/11B and FIN smag value to rego value using RegoDocumentType enum?

What I have tried:

Here's my enum:

public enum RegoDocumentType {
    NRIC_11B("NRIC/11B", IdentityType.NRIC.toValue()),
    FIN("Employment Pass", IdentityType.EM_PASS.toValue()),
    ;

    private static final Map<String, RegoDocumentType> BY_SMAG_VALUE = new HashMap<>();

    static {
        for (RegoDocumentType identityType : values()) {
            BY_SMAG_VALUE.put(identityType.getSmagValue().toLowerCase(), identityType);
        }
    }

    private final String smagValue;
    private final String regoValue;

    RegoDocumentType(String smagValue, String regoValue) {
        this.smagValue = smagValue;
        this.regoValue = regoValue;
    }

    public String getSmagValue() {
        return smagValue;
    }

    public String getRegoValue() {
        return regoValue;
    }

        public static RegoDocumentType getBySmagValue(String smagValue) {
        return BY_SMAG_VALUE.get(smagValue.toLowerCase());
    }
}
Posted
Comments
CHill60 8-Feb-21 4:23am    
I'm really struggling to understand what your problem is. Can you just write down what you are trying to do - without code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900