This discussion is archived
1 2 3 4 Previous Next 46 Replies Latest reply: Apr 21, 2009 10:56 AM by 807588 Go to original post RSS
  • 30. Re: problem while formatting data from csv file to another csv file
    807588 Newbie
    Currently Being Moderated
    Thanks for your great response.

    It was really helpful for me.

    My problem was quite different, I could not explain it properly.

    Here is the actual problem.
    My input file will be like this:-
    Input.csv
    
    LEVEL,1,1,23,DMY,200,198,2
    LEVEL,1,1,23,4AS,658,657,1
    LEVEL,1,1,23,5ON,214,212,2
    LEVEL,1,2,24,DMY,1232,1230,2
    LEVEL,1,2,24,4AS,735,730,5
    LEVEL,1,2,24,5ON,650,645,5
    LEVEL,1,1,25,DMY,200,198,2
    LEVEL,1,1,25,4AS,658,657,1
    LEVEL,1,1,25,5ON,214,212,2
    LEVEL,1,2,26,DMY,1232,1230,2
    LEVEL,1,2,26,4AS,735,730,5
    LEVEL,1,2,26,5ON,650,645,5
    LEVEL,1,1,27,DMY,200,198,2
    LEVEL,1,1,27,4AS,658,657,1
    LEVEL,1,1,27,5ON,214,212,2
    LEVEL,1,2,28,DMY,1232,1230,2
    LEVEL,1,2,28,4AS,735,730,5
    LEVEL,1,2,28,5ON,650,645,5
    LEVEL,1,1,29,DMY,200,198,2
    LEVEL,1,1,29,4AS,658,657,1
    LEVEL,1,1,29,5ON,214,212,2
    LEVEL,1,2,30,DMY,1232,1230,2
    LEVEL,1,2,30,4AS,735,730,5
    LEVEL,1,2,30,5ON,650,645,5
    ELASTICITY,1,1,23,DMY,200,198,2
    ELASTICITY,1,1,23,4AS,658,657,1
    ELASTICITY,1,1,23,5ON,214,212,2
    ELASTICITY,1,2,24,DMY,1232,1230,2
    ELASTICITY,1,2,24,4AS,735,730,5
    ELASTICITY,1,2,24,5ON,650,645,5
    ELASTICITY,1,1,25,DMY,200,198,2
    ELASTICITY,1,1,25,4AS,658,657,1
    ELASTICITY,1,1,25,5ON,214,212,2
    ELASTICITY,1,2,26,DMY,1232,1230,2
    ELASTICITY,1,2,26,4AS,735,730,5
    ELASTICITY,1,2,26,5ON,650,645,5
    ELASTICITY,1,1,27,DMY,200,198,2
    ELASTICITY,1,1,27,4AS,658,657,1
    ELASTICITY,1,1,27,5ON,214,212,2
    ELASTICITY,1,2,28,DMY,1232,1230,2
    ELASTICITY,1,2,28,4AS,735,730,5
    ELASTICITY,1,2,28,5ON,650,645,5
    ELASTICITY,1,1,29,DMY,200,198,2
    ELASTICITY,1,1,29,4AS,658,657,1
    ELASTICITY,1,1,29,5ON,214,212,2
    ELASTICITY,1,2,30,DMY,1232,1230,2
    ELASTICITY,1,2,30,4AS,735,730,5
    ELASTICITY,1,2,30,5ON,650,645,5
    I need output in this manner:-
                                 
    output.csv   
    LEVEL,     1,1,23,200, 658, 214, 198, 657, 212, 2  , 1  , 2  ,
    LEVEL,     1,2,24,1232,735, 650, 1230,730, 645, 2  , 5  , 5  ,
    LEVEL,     1,1,25,200, 658, 214, 198, 657, 212, 2  , 1  , 2  ,
    LEVEL,     1,2,26,1232,735, 650, 1230,730, 645, 2  , 5  , 5  ,
    LEVEL,     1,1,27,200, 658, 214, 198, 657, 212, 2  , 1  , 2  ,
    LEVEL,     1,2,28,1232,735, 650, 1230,730, 645, 2  , 5  , 5  ,
    LEVEL,     1,1,29,200, 658, 214, 198, 657, 212, 2  , 1  , 2  ,
    LEVEL,     1,2,30,1232,735, 650, 1230,730, 645, 2  , 5  , 5  ,
    ELASTICITY,1,1,23,200, 658, 214, 198, 657, 212, 2  , 1  , 2  ,
    ELASTICITY,1,2,24,1232,735, 650, 1230,730, 645, 2  , 5  , 5  ,
    ELASTICITY,1,1,25,200, 658, 214, 198, 657, 212, 2  , 1  , 2  ,
    ELASTICITY,1,2,26,1232,735, 650, 1230,730, 645, 2  , 5  , 5  ,
    ELASTICITY,1,1,27,200, 658, 214, 198, 657, 212, 2  , 1  , 2  ,
    ELASTICITY,1,2,28,1232,735, 650, 1230,730, 645, 2  , 5  , 5  ,
    ELASTICITY,1,1,29,200, 658, 214, 198, 657, 212, 2  , 1  , 2  ,
    ELASTICITY,1,2,30,1232,735, 650, 1230,730, 645, 2  , 5  , 5  ,
    In above output file, first four columns are key for each row. First it checks for records containing same key, if it finds then it will put 5th value from each row, then 6th value and then 7th value from each row. for example for first three records from input.csv file key is LEVEL,1,1,23 and it will read 5th value from each row i.e. 200,658,214 then 6th value from each row i.e. 198, 657, 212, and then 7th value from each row i.e. 2 , 1 , 2, .
    The same procedure is followed for each line.

    Please respond with sample code.

    Thanks.
  • 31. Re: problem while formatting data from csv file to another csv file
    807588 Newbie
    Currently Being Moderated
    You really need to create the spec.'s to be able to implement the algorithm otherwise we or you don't know what you're going at
  • 32. Re: problem while formatting data from csv file to another csv file
    807588 Newbie
    Currently Being Moderated
    Sorry i am not able to understand what you want to convence to me.
    what you really wants me to do?
    Please tell me what to do?

    Edited by: JavaMani on Apr 23, 2009 12:02 AM
  • 33. Re: problem while formatting data from csv file to another csv file
    r035198x Pro
    Currently Being Moderated
    Assuming that I understood your algorithm correctly, here is a probably inefficient but transparent algorithm

    1.) Read all lines into an ArrayList<String>.
    2.) Read the ArrayList extracting keys only and add the keys to a Set<String>. In this step all you do is read the first 3 values and add them to the Set<String>
    3.) Read the ArrayList values again this time extracting the values to be appended to your Set<String> values.
  • 34. Re: problem while formatting data from csv file to another csv file
    807588 Newbie
    Currently Being Moderated
    That's really correct.

    Before posting this issue in forums I also created a same algorithm. but problem I am facing is that the Key value can me in multiple row. I am unable to put logic in such a way that i can combine all row's containing same Key to a single row.
    Please help me out.
    Thanks
  • 35. Re: problem while formatting data from csv file to another csv file
    r035198x Pro
    Currently Being Moderated
    That is not a problem at all because you would use a Set for the keys. When you add a key that is already there it won't be added again because a Set contains unique values. So Just read the key parts and add them to the Set<String> and you would have a Set of unique keys.
  • 36. Re: problem while formatting data from csv file to another csv file
    807588 Newbie
    Currently Being Moderated
    That's fine.

    I am able to get unique key set. Using unique key set not able to combine the multiple values from different row's, which has the same key.
    Let's take a input.csv file example:-
    LEVEL,1,1,23,DMY,200,198,2
    LEVEL,1,1,23,4AS,658,657,1
    LEVEL,1,1,23,5ON,214,212,2
    for the above code key will be LEVEL,1,1,23
    Now I have to marge all three rows because all has the same key.
    So the output should be like this:-
    LEVEL,1,1,23,200,658,214,198,657,212,2,1,2
    200 is from first row, 658 from second row and 214 from third row. this repeats for other values also.
    This is what I wants to achieve

    Thanks.
  • 37. Re: problem while formatting data from csv file to another csv file
    r035198x Pro
    Currently Being Moderated
    You have to read the ArrayList again and then locate the key in the Set for which the record belongs to. You then extract the value you want (say fifth) and append it to the key. You then run through the ArrayList again this time adding the sixth values to the key and again for the seventh values. That is why I said that it would not be efficient.
    It can be improved but it's probably best that you get the correct output first.
  • 38. Re: problem while formatting data from csv file to another csv file
    800308 Newbie
    Currently Being Moderated
    Please respond with sample code.
    Did you actually read any of the reponses you've already got? And you can't think how to adapt them to your requirements?

    Jeezus! I did all that work for just another "sned me teh codez" a-hole.

    McDonalds are still hiring, I think. Good luck with the interview.

    Sheesh! Keith.
  • 39. Re: problem while formatting data from csv file to another csv file
    807588 Newbie
    Currently Being Moderated
    I can not use HashMap because I want records in order. But HashMap does not guarantee for Data order.
    I am using ArrayList for the same.

    Can any one send same sample code to implement the functionality posted in previous messages?

    Thanks.
  • 40. Re: problem while formatting data from csv file to another csv file
    r035198x Pro
    Currently Being Moderated
    JavaMani wrote:
    Can any one send same sample code to implement the functionality posted in previous messages?

    Thanks.
    That is simply not going to happen. You have been given pointers and usable code already. You are going to have to start implementing the algorithm yourself and post if you get problems with your code.
  • 41. Re: problem while formatting data from csv file to another csv file
    807588 Newbie
    Currently Being Moderated
    You have more than enough of samples of how the logic looks when developing the algorithm to do what you need, if we do it for you, you might be as lucky next time you run into a problem like this one. First write out the spec.'s you'd expect the program would have to follow to meet your needs and then check it and then try to implement it. Ask us when you have a problem with a specific implementation of your spec.'s.
  • 42. Re: problem while formatting data from csv file to another csv file
    800308 Newbie
    Currently Being Moderated
    If you can't figure out how to turn an ArrayList into a set then go tell you're boss that you're very sorry for wasting his time, but you simply can't do the job he's hired you to do, because you're simply not capable of doing it. Then offer him a full refund of any payment he has given you to date. I amost guarantee you that your boss will appreciate your honesty; and far from being angry s/he may even attempt to find another place for you... raw intelligence is not the only attribute that's worth hiring, it's just the one that happens to be the chief prerequisite for computer programming... and for every programmer there's three or four "support staff"... maybe s/he needs a good tester... testers need to be honest.

    Pretending to do a job which is beyond you is dishonest. Harsh but true.

    Cheers. Keith.
  • 43. Re: problem while formatting data from csv file to another csv file
    807588 Newbie
    Currently Being Moderated
    Thanks guy's...

    I did it with proper class structure.

    Now, i just want to know if any Collection class available in java that provide the same functionality as HashMap but also promise for order?

    Please respond ASAP.

    Thanks & Regards,
    Manish
  • 44. Re: problem while formatting data from csv file to another csv file
    807588 Newbie
    Currently Being Moderated
    One more question about java concept.
    If i create two different object of class containing the same value, and the if i compare both object, will it return true?