Does anyone have thoughts on what's superior, EnumMap
or Properties
(or at least in my situation?) I am using a 3rd party software package that communicates between my code and their application using their method like so:
TheirRuntime.getInstance().getParameter(String paramName)
Currently I have created an enum
that works like this:
public enum MyEnum {
FOO_BAR ("fooBar"), BAZ_QUUX ("bazQuux");
private final String varName;
private MyEnum(String varName) {
this.varName = varName();
}
public String varName() {
return varName();
}
}
Then I store the values in an EnumMap<MyEnum, Double>
, which gets updated when the user changes something. My architecture is slightly more complicated than this but I'm omitting some details for the sake of SSCCE. Though I will mention that I load the values with something like:
for (MyEnum me : MyEnum.values()) {
TheirRuntime.getInstance().getParameter(me.varName());
}
What I'm wondering is, would it make more sense to use Properties
? This question has come up because I'm trying to build a test framework that doesn't involve the 3rd party software at all, and I'm trying to figure a good, easy way to load the parameters that doesn't use any 3rd party API calls, and a Properties
file seems an easy way to go, which makes me wonder if I should just use Properties
in the main class.
Thoughts?
Benefits of Enum are clear:
It provides you enum literals. You can use them to catch "wrong key" issues at compilation level.
Properties allow you flexibility - for example - you can read them from a file.
The big question is - how sure are you that the set of literals provided by the enum is fixed, and will not change?
For example, our system has a set of enum values, and since we're an open source project, we would like to build a plugin on top of it that theoretically should have used the enum values,
But plugin writers will not be able to use the original enum, as it has a fix set of literals, so either we modify our enum to a properties object, and let plugin writers register their "literals",
or we have to provide a supplementary system to our enum.
I'm sorry that I don't have a "clear cut" solution here.