This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Hashmap question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hashmap question" Watch "Hashmap question" New topic
Author

Hashmap question

Edward Jalbert
Greenhorn

Joined: Jan 12, 2007
Posts: 3
Still really new to programming in general, However, my motto is if I can think it it is either being done or been done.

I work with an interface engine which uses java. A lot of the tools are in the development gui. Currently working with HL7.

We use a propeties file which contain the key prefix for a data look up.

The data I have been given is to do a look up for the value of field "A" + field "B"

So on the properties look up we would have
key.trx.AB=DOCTYPE

I have created a variable to hold the value of the two concatenated fields and then place the value in the outgoing message.

example input
A|B||||

Output
DOCTYPE||||


There are two other additional values for the report header and I was wondering is it possible to break parse the value into 3 variables and add them to the orginal key lookup? Each document type could have 2 headers associated to it.

If AB=DOCTYPE,HEADER1,HEADER2
So the output would look like

DOCTYPE|HEADER1|HEADER2||

Sorry for no code written and I would appreciate any guidance on were to start,I guess I am hoping to be able to create one variable and then parse it out to the appropriate fields instead of 3 differnt variables. I was not sure if it was possible to put a delimeter in the key look up and then do a substring of the variable to the additional fields.

Thanks in advance,
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14279
    
  21

So you are trying to parse / generate HL7 format using Java? I have only a very faint idea of what HL7 is (I remember someone mentioning it on the forums here before).

"However, my motto is if I can think it it is either being done or been done."

Indeed, it is already being done. Have you tried searching with Google for "Java HL7"? You're not the first person in the world who is trying to do something with HL7 in Java. Why not use one of the existing libraries or projects instead of trying to invent everything yourself?

Found with Google:

HAPI - open-source HL7 parser in Java
HL7 Tools, Utilities and Resources
Light HL7 Library
Official HL7 website
[ March 21, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Edward Jalbert
Greenhorn

Joined: Jan 12, 2007
Posts: 3
Thanks for the resource links.

Actually I am not trying to parse but perform string manipulation and need to set certain fields based on a look up to a properties file. So I was just curious if there was away based on the return to parse the data out instead of creating three separate key entries.

Jumped ahead a bit in the head first book and assumed I am working with some variation of either an array list,link list or hashmap.

I have a variable which holds the return of the look up and was not sure if there was away to parse it to differnt substrings, again read ahead a little further than I should but was thinking of the string tokenizer.

example var contains the following
ABC,header1,header2

Thanks again for your help
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14279
    
  21

Ok, so is your question about parsing a string like "ABC,header1,header2" into parts delimited by commas? One of the easiest ways to do this is to use the split(...) method in class String. It takes a regular expression as an argument. Example:

You can also use StringTokenizer to parse a string.
[ March 21, 2007: Message edited by: Jesper Young ]
Edward Jalbert
Greenhorn

Joined: Jan 12, 2007
Posts: 3
Thank you very much, this is exactly what I was asking. Sorry for taking the long way to ask a question.

Again thanks for all the help.
 
jQuery in Action, 2nd edition
 
subject: Hashmap question