Snippets Collections
final String id = Hashing.murmur3_32().hashString(url, StandardCharsets.UTF_8).toString();
public enum FamilyMemberTypes {

    CHILD("CHILD", "Child"),
    FTH("FTH", "Father"),
    MTH("MTH", "Mother"),
    MGRMTH("MGRMTH", "Maternal Grandmother"),
    PGRMTH("PGRMTH", "Paternal Grandmother"),
    MGRFTH("MGRFTH", "Maternal Grandfather"),
    PGRFTH("PGRFTH", "Paternal Grandfather");

    private final String key;
    private final String value;

    FamilyMemberTypes(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    //Lookup table
    private static final Map<String, String> lookup = new HashMap<>();

    //Populate the lookup table on loading time
    static {
        for (FamilyMemberTypes familyMemberTypes : FamilyMemberTypes.values()) {
            lookup.put(familyMemberTypes.getKey(), familyMemberTypes.getValue());
        }
    }

    //This method can be used for reverse lookup purpose
    public static String getValue(String key) {
        return lookup.get(key);
    }

}
enum class PaymentOption {
    CASH,
    CARD,
    TRANSFER
}

fun PaymentOption.startPayment(transaction: TransactionData) {
    when (this) {
        PaymentOption.CASH -> showCashPaimentInfo(transaction)
        PaymentOption.CARD -> moveToCardPaymentPage(transaction)
        PaymentOption.TRANSFER -> {
            showMoneyTransferInfo()
            setupPaymentWatcher(transaction)
        }
    }
}
star

Wed Dec 22 2021 11:51:09 GMT+0000 (UTC)

#java #enum
star

Mon Dec 20 2021 12:45:44 GMT+0000 (UTC)

#java #enum
star

Thu Jun 17 2021 13:30:51 GMT+0000 (UTC) https://blog.kotlin-academy.com/enum-vs-sealed-class-which-one-to-choose-dc92ce7a4df5

#kotlin #extensionfunction #enum

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension