I have a set of unformatted strings that I need to come out formatted. I have the full list for both.
Here's a subset of it:
"in room" => "ROOM"
"in big room" => "BIG ROOM"
"in building" => "BUILDING"
"in street" => "STREET"
"in house" => "STANDARD"
"Room box" => "ROOM"
"Big room box"=> "BIG ROOM"
"Street box" => "STREET"
"Box" => "STANDARD"
default value => "STANDARD"
I was told to use an enum
in so that I don't have tons of if
s, but I'm not sure how that would help. My enum will look something like this:
public enum BoxLocation {
STANDARD("STANDARD"),
ROOM("ROOM"),
BIG_ROOM("BIG ROOM"),
...
But I don't get how that will help avoiding tons of ifs.
How should I bind one or more (never more than 2, except for the default value) unformatted strings to a formatted string, what the cleanest way? I was thinking something like:
if(boxLocation.equals("in room") || boxLocation.equals("Room box"))
boxLocation = BoxLocation.ROOM;
But then how does it help to have an enum, couldn't I just use this?
boxLocation = "ROOM";
EDIT: Some formatted values have spaces, that changes things with enums. I edited the list.