I have to "translate" codes with a conversion table like this:
| symbol | translation | | 1 | 3 | | 2 | 4 | | 3 | 6 | | 4 | 5 | | 5 | 2 | | 6 | 1 | | 7 | 1 |
My first idea was to use a Map
associating each symbol to its translation and to load the table from a database or a text/xml file. Is there a better way? Doesn't have to be lightning fast, just easy to maintain and test.
TIA.
Map is ideal unless your mapping table/file may change after you have loaded it in the Map.
In other words, if your association is fairly static, and can accept having to restart the application when it changes, go for a simple map.
Otherwise you have to think of some kind of notification mechanism so that the map can be updated (or even just reloaded) without relaunching the app.
Depending on the situation, you may want to expose a simple external call to refresh it, or poll the underlying file/table at regular intervals, or some combination of these.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With