This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi this is srinivas . i have an assignment can anybody help
Here is the assignment.
public String MethodName(String query, List listValues) { //Here your code
}
There should be a test method i.e main in the class you are going to create Tasks to be done: 1.Query =" VouchNumber='~VouchNum~' AND BusinessUnit='~BU~' AND InvoiceNumber='~IN~' " HashMap will contain key value pair all strings VouchNum=00005, BU=0231,IN=3443 Output should be " VouchNumber='00005' AND BusinessUnit='0231' AND InvoiceNumber='3443' " 2. Query =" VouchNumber='~VouchNum~' AND BusinessUnit='~BU~' AND InvoiceNumber='~IN~' " HashMap will contain key value pair all strings VouchNum=00005, IN=3443 Output should be " VouchNumber='00005' AND InvoiceNumber='3443' "
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
post what your specific problem is, and your attempt at a solution
sudhasrinivas pallam
Ranch Hand
Joined: Oct 06, 2008
Posts: 37
posted
0
actually query is a string String query =" VouchNumber='~VouchNum~' AND BusinessUnit='~BU~' AND InvoiceNumber='~IN~'; HashMap m contains the key-value pairs as VouchNum=00005, BU=0231,IN=3443
iam passing HashMap object and query as arguments to the MethodName() as MethodName(String query,HashMap m)
now i have to get output as
" VouchNumber='00005' AND BusinessUnit='0231' AND InvoiceNumber='3443' "
how can i parse the query and retrive the data between ~ ~
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
4
posted
0
Welcome to JavaRanch. There are lots of different ways to parse that String. Look through the String class, the Scanner class, and the Java Tutorial about Regular Expressions.
sudhasrinivas pallam
Ranch Hand
Joined: Oct 06, 2008
Posts: 37
posted
0
thanks for the support can you help out this how can i retrive one by one key values from the HashMap and compare it with string variable
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
4
posted
0
You would have to get a Set of the Map.Entry objects then iterate through it for the key, but that isn't how you use a Map at all.
You "put" the key and value in, then you "get" with the key and the value reappears.
sudhasrinivas pallam
Ranch Hand
Joined: Oct 06, 2008
Posts: 37
posted
0
i tried in this way it is workin almost with some extra stuff i need to print only resultant string
[edit]Add code tags and remove excess whitespace. CR[/edit] [ October 07, 2008: Message edited by: Campbell Ritchie ]
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
4
posted
0
Good progress, then?
Please use a more informative subject title in future, and find out about code tags; I have added tags so you can see how much easier your code is to read.
cR
sudhasrinivas pallam
Ranch Hand
Joined: Oct 06, 2008
Posts: 37
posted
0
thanks Campbell Ritchie
can you please help me out to get this output
" VouchNumber='00005' AND BusinessUnit='0231' AND InvoiceNumber='3443' "
from the above code . iam getting an updation result please help me out
If you put the code I posted together, you will come up with this:
and the modified query is:
sudhasrinivas pallam
Ranch Hand
Joined: Oct 06, 2008
Posts: 37
posted
0
Thanks for your support and code Rene Larsen
finally i tried using Strings and i got the result the code is
Once again thanks for your support
sudhasrinivas pallam
Ranch Hand
Joined: Oct 06, 2008
Posts: 37
posted
0
Thanks a lot for support
i have another case where i have to get out put like this
" VouchNumber='00005' AND InvoiceNumber='3443' "
and the case is CASE2:- Query =" VouchNumber='~VouchNum~' AND BusinessUnit='~BU~' AND InvoiceNumber='~IN~' " HashMap will contain key value pair all strings VouchNum=00005, IN=3443 Output should be " VouchNumber='00005' AND InvoiceNumber='3443' "
help me in getting this
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
4
posted
0
Is this a College assignment? This is getting more and more difficult for you. Suggest you are going to have to pass the tokens you are looking for as parameters somewhere, so your method actually looks for the preceding split String matching "VouchNumber" or "InvoiceNumber".
You can pass a String[] with those tokens in, look for them in the String, find the ~ after that, get the contents of the ~---~ and put them together.