Last active
February 1, 2016 08:33
-
-
Save birchestx/5bcd2ffcf1895836ef53 to your computer and use it in GitHub Desktop.
Java singleton using enum and hashmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum DomesticShipment { | |
INSTANCE; | |
private Map<String,String> domesticCountry; | |
DomesticShipment() { | |
domesticCountry = new HashMap<>(); | |
domesticCountry.put("ausPost","AU"); | |
} | |
public boolean isDomestic(String carrierType, String country) { | |
return domesticCountry.containsKey(carrierType) && | |
domesticCountry.get(carrierType).equalsIgnoreCase(country); | |
} | |
} | |
To use: | |
DomesticShipment.INSTANCE.isDomestic(carrier, destinationCountry); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment