Issue
I want to shorten the if conditions. Is there any alternative other than switch case?
public void check(String name){
String parentFolder = "";
if(name.matches("birds"))
parentFolder = birdPFUuid;
if (name.matches("dogs"))
parentFolder = dogPFUuid;
if (name.matches("cats"))
parentFolder = catPFUuid;
if (name.matches("vehicles"))
parentFolder = vehiclesPFUuid;
}
Thank you
Solution
You can use a map data structure to map the parent folder UUID to the dataset name.
Map<String, String> uuidMap = new HashMap<>();
uuidMap.put("birds", birdPFUuid);
uuidMap.put("dogs", dogPFUuid);
uuidMap.put("cats", catPFUuid);
uuidMap.put("vehicles", vehiclesPFUuid);
public void check(String name){
String parentFolder = uuidMap.get(name);
}
Answered By - ANISH SAJI KUMAR
Answer Checked By - David Marino (JavaFixing Volunteer)