Skip to content

Instantly share code, notes, and snippets.

@birchestx
Last active February 1, 2016 08:33
Show Gist options
  • Save birchestx/5bcd2ffcf1895836ef53 to your computer and use it in GitHub Desktop.
Save birchestx/5bcd2ffcf1895836ef53 to your computer and use it in GitHub Desktop.
Java singleton using enum and hashmap
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