0

I want to have a small data structure which resembles a relational db table with 3 columns. In fact, it's like a matrix where I want to select the value from the third column when the first two match e.g.

Edit: formatted

Michael John 1 Michael Jeremy 3 Jeremy John 4

and I want to select 3 when the the names of the two persons (according to the data selected) is

Michael and Jeremy.

I do not want to keep it in the DBMS since the data is two small (between (between 20 - 30 rows), but I do want to keep it configurable to allow for modifications - as such I am avoiding to use a Java data structure such as Map / list

I am using Spring Framework.

Any suggestions?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Abby
  • 403
  • 2
  • 6
  • 18

1 Answers1

0

In fact, the in memory representation of your data structure is probably going to look like a map. The key or hash is going to be a combination of user names in both directions and the value will be the number.

So your map will have entries like this:

 {"Jeremy_John":4}
 {"John_Jeremy":4}

Of course you can use any separator. And depending on your use case, you may not have to hash in both directions.

By configurable, I'm assuming you mean editable in your spring config file. You could could load a list into a bean constructor something like this:

<list>          
    <value>"Jeremy,John,4"</value>
</list>

Then parse those strings in your constructor to create your map. The map would have two entries per line: John, Jeremy and the reverse.

If you did that, then you could also keep your data in an external csv file.

There are a lot of possibilities including using generics for your properties or even a special class that wraps each entry. It would have a constructor that accepts two strings and a number. You could then have a list of those in your spring file.

People often use this pattern to use spring as a low-fi business rules engine.

Robert Moskal
  • 21,737
  • 8
  • 62
  • 86