Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert/translate information?

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.

like image 916
Manrico Corazzi Avatar asked Jun 04 '10 08:06

Manrico Corazzi


1 Answers

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.

like image 68
p.marino Avatar answered Oct 23 '22 15:10

p.marino