if the previous action that is being executed has finished its execution
stored them in separate ArrayLists.
Norm Radder wrote:Can the class that holds the action have a flag or state variable to remember that?
Why separate? Are you looking at parallel lists? A bad idea. Build a class to hold all the bits needed.
the file can be changed
I never know if a previous action had finished execution.
by checking if the previous action that is being executed has finished
Norm Radder wrote:Not sure what that means. Can the file be changing while you are reading it? In other words, if you read the file into memory, the contents of the file can be changed and what was read is no longer valid.
Isn't that a requirement? If you can't tell that, how can you start any actions?
need to check if every single one of them is valid.
Norm Radder wrote: Can you describe what the three columns of data in the file is and how the three columns are related?
What needs to be tested for validity?
Norm Radder wrote:Ok, what is your algorithm for detecting if an action is valid?
What happens to invalid actions? Rejected and ignored or ???
Norm Radder wrote:What is The final object: a report listing the actions and whether they are valid or not?
Norm Radder wrote:Not sure what the counter is for.
Isn't testing the next action for validity a simple compare of its start time against the current action's start time plus duration? The start time must be afterwards.
keep track of all the attributes of each action, meaning when I need check the previous action vs current action times, how do I know which action is previous
Norm Radder wrote:Read the records for the actions, create objects for each action, store the action objects in a list, sort the list by starting time.
When working on any action from the list, the previous one would be at a lesser index.
where would my regex manipulation go
Norm Radder wrote:All the data from a line should go into one object and that object can be saved in a list.
Finish getting the design work done before writing any code.
'remember' each attribute of each line separately
comparing the time+duration?
Norm Radder wrote: When a line is read from the file, it is parsed into the 3 columns and that data is used to create an object. That object is added to a list.
All the attributes of each line are in the object that is saved in the list in the same order they were in the input file.
Each line is one action - first column is start time, second column is "name of action" and 3rd one is the duration
There are three kinds of actuaries: those who can count, and those who can't.
Norm Radder wrote:So this is a new problem: How to extract the 3 pieces of data from an input record:
Each line is one action - first column is start time, second column is "name of action" and 3rd one is the duration
There are probably several ways to parse the input line:
split
regex
other String methods like indexOf
If the first column always ends with a space and the last column always follows a space, something as simple as the String class's indexOf method could work.
The parsing is not a problem for me, as I said I've already done that part using regex,
There are three kinds of actuaries: those who can count, and those who can't.
Norm Radder wrote: I'm confused. If you are able to parse out the three columns of data, what further problems do you have?
Given the three parts from the line, an object to save them would involve calling the object's constructor and passing it the 3 parts.
Please post a small simple program with a String holding a sample record and the code you are using to parse that input String into the three separate parts.
There are three kinds of actuaries: those who can count, and those who can't.
Paul Clapham wrote:What objects are those, then? Right now you're parsing the String, I assume correctly, but you're just adding the parsed data to three ArrayLists. But you should have a class which encapsulates those three parts, shouldn't you? So far I don't believe we've seen a declaration of any such class in what you have posted.
Norm Radder wrote:Change your testing code to just print out each of the three values so we can easily see that they have been parsed.
Note: I did the above and the posted code did not work.
1) had compiler error
2) did not find the second time
Paul Clapham wrote:What objects are those, then? Right now you're parsing the String, I assume correctly, but you're just adding the parsed data to three ArrayLists. But you should have a class which encapsulates those three parts, shouldn't you? So far I don't believe we've seen a declaration of any such class in what you have posted.
Trent Green wrote:How do I encapsulate those parts in an object?
Paul Clapham wrote:The class which Piet posted about three or four posts back should do for a start.
Trent Green wrote:I know how to create such a simple class, but I thought that the encapsulation of the attributes should be in the part of the code where I read my file and parse it using regex, or am I wrong?
I was copying my code
Paul Clapham wrote:Now if your question was whether you should parse the data into its components and pass them to the class separately, or whether you should pass the unparsed string to an object of the class and have it do the parsing, well, again that's a design question. If your class is just a simple container for the data items, then it shouldn't be responsible for parsing them out of a particular format. However if your class is intended to know everything there is to know about, about whatever those three things are supposed to represent, then you might want to have it do the parsing.
Right now if I were you I'd just go for the simple container idea. It may be that as time goes on you may find a need for something more complex which manages the relationships among objects of that class, and so on. Such requirements would usually come out of a design process.
parsing to the attributes won't be as easy and that is what I can't figure out how to do.
If the first column always ends with a space and the last column always follows a space, something as simple as the String class's indexOf method could work.
Norm Radder wrote:Will this work:
If the first column always ends with a space and the last column always follows a space, something as simple as the String class's indexOf method could work.
Find the first space, use substring to get what is before it. Use lastIndexOf to find the last space and use substring to get what is after it.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:I'm at a loss here. The splitting was not the problem, was it? The splitting you gave a few posts ago concerns a complete other format, I really don't see what, after three topics, still is the problem. Throwing in the towel.
Consider Paul's rocket mass heater. |