?
Solved

Best way to find data in a variable length ASCII text area where the property data (key/values pairs) may be always different

Posted on 2006-04-25
8
Medium Priority
?
198 Views
Last Modified: 2010-03-31
What would the best way to find items in a variable length ASCII text area where the data (is set up like a property file with key/values pairs but may be always different).  I will know the different types of key/value pairs but they might change (new ones added or old ones removed)

say text area could have
First Name=Chris
Last Name=Willis

Next text area I am sent could have
Street Name=100 Main Street
City Name=New York

Next one could have
userid=2010
password=password


I know I probably should treat it as a property file.. using Properties class and use the get method, but where would be the best way/place to put the items you are looking for in an Araylist?

Or would you just move the text area over to a hashmap and try to get the key/value pairs from there?
The message area will only have one of the 3 at a time though, so don't know the best way without searching the text area with all of them...

any suggestions?
ryno71
0
Comment
Question by:ryno71
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16535595
>>but where would be the best way/place to put the items you are looking for in an Araylist?

How do you mean? They'd already be in a Map if you're using Properties
0
 

Author Comment

by:ryno71
ID: 16535667
Let me rephrase I am given an object that contains a variable length ascii text area...  should I place this into a hashmap so I could use the Properties class (best way) AND what would be the best way to search for the 3 types... as when I have firstname I would know last names would be next or if I had username I would know password would be next, etc.


0
 

Author Comment

by:ryno71
ID: 16536213
The text area would look something like this..


FirstName=Chris
LastName=Willis
FirstName=John
LastName=Taylor
FirstName=John
LastName=Gleese

or

Street Name=100 Main Street
City Name=New York
Street Name=200 Main Street
City Name=Denver
Street Name=500 Main Street
City Name=York

Should i place the items I want to search for in an ArrayList  as (FirstName,LastName)  (Street Name, City NAme) and place the values after I find them back in that type of format in an arraylist?
John,Gleese
John,Taylor

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 30

Expert Comment

by:Mayank S
ID: 16536781
>> should I place this into a hashmap so I could use the Properties class (best way)

Properties is related to HashMap in a way, that both are maps. Properties is synchronized (thread-safe) so don't bother about using a HashMap.

>> when I have firstname I would know last names would be next

In all maps, the order becomes irrelevant. So just search based on the key.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 800 total points
ID: 16537516
You would probably be best to keep two views of the data
a. a single String that you can use to do pattern matching
b. a Properties view so you can retrieve key/value pairs
0
 
LVL 92

Assisted Solution

by:objects
objects earned 800 total points
ID: 16539004
try the following to load your map:

Properties map = new Properties();
map.load(new ByteArrayInputStream(textArea.getText().getBytes()));

you can then get the set of keys using:

Set keys = props.keySet();

And get a value using:

String value = map.getProperty(key);
0
 

Author Comment

by:ryno71
ID: 16539375
Luckily for me I am being passed a Property list... so I wont need to do anything fancy..

Could just do an enumeration then with a typical while ( enum.hasMoreElement()) and put the values into an Arraylist.  I will just grab the keys from a configuration file.  I always forget the K.I.S.S rule!

Thanks for the help guys...
ryno71
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16541545
:-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question