Results 1 to 9 of 9
Thread: String parsing
- 02-28-2012, 09:50 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 51
- Rep Power
- 0
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
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: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"); ...
- 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.
- 02-28-2012, 11:07 PM #2
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?
- 02-28-2012, 11:14 PM #3
Re: String parsing
Cross posted at String parsing - Java | DaniWeb
- 02-29-2012, 11:32 PM #4
Member
- Join Date
- Feb 2010
- Posts
- 51
- Rep Power
- 0
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
- 03-01-2012, 12:05 AM #5
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.
- 03-01-2012, 11:27 AM #6
Member
- Join Date
- Feb 2010
- Posts
- 51
- Rep Power
- 0
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 ...
- 03-01-2012, 11:58 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
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.
- 03-01-2012, 01:16 PM #8
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.
- 03-01-2012, 02:13 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Similar Threads
-
String Parsing Problem
By jamess in forum New To JavaReplies: 3Last Post: 12-06-2010, 09:59 AM -
Problem with string parsing.
By dc0m in forum New To JavaReplies: 5Last Post: 08-31-2010, 06:25 PM -
problems with parsing a string into int,
By bigj in forum New To JavaReplies: 3Last Post: 01-06-2010, 10:32 PM -
Parsing string and simple calculation
By sapina007 in forum Advanced JavaReplies: 4Last Post: 08-21-2009, 12:07 PM -
parsing numbers in a string
By rsoler in forum Advanced JavaReplies: 4Last Post: 03-31-2009, 06:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks