Results 1 to 9 of 9

Thread: String parsing

  1. #1
    gedas is offline Member
    Join Date
    Feb 2010
    Posts
    51
    Rep Power
    0

    Default String parsing

    Hi guys,

    i have been having some problems parsing a list of strings.
    lets say i have a list that has the following strings
    Java Code:
    List<String> list = new ArrayList<String>();
     
    list.add("Process A Started");
    list.add("Process B Started");
    list.add("Process B Finished");
    list.add("Process A Started");
    list.add("Process C Started");
    list.add("Process D Started");
    list.add("Process C Finished");
    list.add("Process A Finished");
    list.add("Process B Started");
    list.add("Process D Finished");
    list.add("Process A Started");
    ...
    what i need is to come up with the logic that would check whether the process A/B/C/D.. has started and has it finished. if it started and not finished that means it failed. The following would be the logic required:
    • If process started it has to finish

    • Process can not start again if it already started.

    • if a process started other process can run and finish before the specific process finished



    please help me on sorting this out.

    Thanks You.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,415
    Rep Power
    25

    Default Re: String parsing

    Please explain your String parsing problem.
    What do you mean by "parsing"?
    What results do you want from parsing the Strings?


    What does this have to do with processes?

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,415
    Rep Power
    25

    Default Re: String parsing


  4. #4
    gedas is offline Member
    Join Date
    Feb 2010
    Posts
    51
    Rep Power
    0

    Default Re: String parsing

    Ok, now i see where the confusion is coming from.

    well you are right list of strings has got nothing to do with processes, however in my case it kind of does.

    i daily receive a txt file via email containing hundreds of lines that state a process name and its status (start/finish) also time of start or finish.
    Something like below:

    Process A started 12:02:22
    Process B started 12:03:11
    Process B finished 12:14:00
    Process C Started 12:15:11
    Process A finished 12:15:23
    Process C Started 12:16:28

    the above processes operate remotely(i have no access to their code).
    they perform various tasks.
    only info that i get about them is displayed above, (the info i get is when it started and when it finished)
    most of those processes run few times a day, some run every minute, some run for hours, some run for seconds.
    In some cases those processes fail, that means that their start message is logged but the finish message isnt, because it failed.
    my job is to monitor those messages that were logged by those processes, however there are hundreds of these processes, which means there are hundreds of messages and such monitoring becomes very impossible.
    what i am trying to come up with is something that would give me a flag if the same process has started twice and did not finish in the middle, meaning that it failed.

    have a look at the sample dump above, process C has started and than it started again, but it never finished,, that means the first time it started, it failed.
    please note same process can start and finish many times however it can not start without finishing.

    please advice me on the required logic and a method that i could use to perform the monitoring described above.

    any advice would be appreciated

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,415
    Rep Power
    25

    Default Re: String parsing

    Use a HashMap to store the status messages for each process in a list. As you get a status message for a process, you could scan the list of messages for that process and find it's current status.
    Or you could have a scheme where instead of a list of the status messages, there is an object/class for each process that you pass the status message to, it maintains the process's status which could be queried.

  6. #6
    gedas is offline Member
    Join Date
    Feb 2010
    Posts
    51
    Rep Power
    0

    Default Re: String parsing

    Thanks for your reply,

    i was thinking about hash map, however if i add a process id as a key and a status as value and than add it again, the value may be overridden by the new value. i just dont see the way i could get this to work.
    However i was thinking of creating an object that stores the process id and the process value, then add this to the hashmap as a value but generating a random key for it, this means i would be able to have a unique key for each message, wich would allow me to differentiate between all the messages. would this work?
    Nonetheless i am still struggling on implementing this ...

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: String parsing

    Working off what Norm says (if I've understoof you correctly), add a Process to a Set keyed by process name/id (whatever) if the process is marked as 'started'.
    If marked as 'finished' then remove from the Set.
    If a process already exists in the Set then flag that (maybe store the original to one side, replacing it in the Set with the new one).
    At the end of the processing of the text file anything left in the Set is Processes that have started but not finished.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,415
    Rep Power
    25

    Default Re: String parsing

    Given a Process status record, get the process's entry from the hashmap.
    If there is not an entry, create and store one in the hashmap
    If there is one, call its setStatus method with the current status record.
    the Process class would internally keep the status of the process.

    The code would NOT simply put the current status record into the hashmap. There would be a class the handled the status record and that would maintain the process's current status.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: String parsing

    I thought they were parsing a text file to find out (at the end) which processes hadn't finished?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. String Parsing Problem
    By jamess in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 09:59 AM
  2. Problem with string parsing.
    By dc0m in forum New To Java
    Replies: 5
    Last Post: 08-31-2010, 06:25 PM
  3. problems with parsing a string into int,
    By bigj in forum New To Java
    Replies: 3
    Last Post: 01-06-2010, 10:32 PM
  4. Parsing string and simple calculation
    By sapina007 in forum Advanced Java
    Replies: 4
    Last Post: 08-21-2009, 12:07 PM
  5. parsing numbers in a string
    By rsoler in forum Advanced Java
    Replies: 4
    Last Post: 03-31-2009, 06:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •