Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Multi-dimensional properties file

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to incorporate a multi-dimensional 'array' in a properties file?

In my situation, I want to look up a key and find associated field values for that key. For example: Name(key), address, phone number, etc.

Thank you.
 
Marshal
Posts: 74661
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would you go through a text file and read name, address, phone number, and put them into a Map with name as "K" and address as "V?" That sounds easy enough. You could incorporate address, phone number, etc into a single class.

Is that what you mean?
 
Master Rancher
Posts: 4599
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since a Properties extends Hashtable, you have only a single key.
To have multiple dimensions, you can create dotted and suffixed key names for each of the sub values. For example:
Name1=john doe
Name1.address=123 river drive
Name1.phone=232-333-3333

Then use string concatenation to build the keys.
 
Mary Shields
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I have is a table that uses a key to get multiple fields related to that key, for example, use 'name' to get the other fields (address, phone number, etc.). The values in the table change rarely, and there are very few entries. Maybe the properties file isn't the way to go?
 
Norm Radder
Master Rancher
Posts: 4599
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure how you use one key to get multiple values from the same table. Surely you need one key per value. Or one table per value.
One way would be to have a record that contains the values as fields. Then the key would return the record with multiple values.
[ July 07, 2008: Message edited by: Norm Radder ]
 
Mary Shields
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I went ahead with the properties file, and delimited the values with commas. Then, used String.split to carve out the individual fields. The amount of data I'm using is trivial, so this works for me.
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd consider creating a subclass of java.util.Properties. It would have an additional method that returns a Map of all those properties whose key starts with a given prefix ("name1" is your example). That can't be much more than 10 lines of code.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic