Reputation: 444
I have a challenge:
Imagine you have a set of messages like this:
Code / Message
200567 = A new user was created
462001 = Unknown client number
...
I'm trying to find the neatest, lightest, and easiest to maintain way to use this messages in java.
The rules are:
Other notes:
So, anybody has ideas?
(Sorry about my lousy English)
Upvotes: 1
Views: 417
Reputation: 24326
I would put this in an enumeration.
public enum MessageType {
NEW_USER("String 123", "A new user was created");
private String code, message;
private MessageType(String code, String message) {
this.code = code;
this.message = message}
I would go for enumerations because they are to be checked into source control, typically in the environments where I work the properties file is meant to be configured by the individual. Such as an ant build properties file.
Upvotes: 1
Reputation: 11549
Your best bet is probably to have a HashMap<string, string>
or HashMap<int, string>
that is a static member of your main class or some other relevant class. Write a properties file and a simple method that is called near the start of the program to populate the HashMap.
http://download.oracle.com/javase/6/docs/api/java/util/HashMap.html
Upvotes: 0
Reputation:
If I had to implemtn this I would use a HashMap. The code are the keys and the message the values.
Upvotes: 1
Reputation: 240918
Go for Properties File. Use ResourceBundle
200567 A new user was created
462001 Unknown client number
Upvotes: 4