![]() |
State transition
Hi,
I have problems with my newsreader and can't reply directly but the last question from Eric Sosman: How is the overall program structured? Would you like to write `if(var.transitioned())' at points of interest, or would you like to "register an observer" to be notified of transition events, or would you like transition events to be queued when they occur and handled later, or what? best meets my problem Ben |
Re: State transition
Ben Engbers wrote:
> I have problems with my newsreader and can't reply directly but the last > question from Eric Sosman: > > How is the overall program structured? Would you like to > write `if(var.transitioned())' at points of interest, or > would you like to "register an observer" to be notified of > transition events, or would you like transition events to > be queued when they occur and handled later, or what? > > best meets my problem And the answer is ... ? For that matter, what is your problem? Since you knew you were posting absent the historic context of your post, why the frak did you omit it in your post? And the point of people asking you a question is to have you answer it. Or by "last question" did you mean that the answer is "what"? In which case you're screwing with us. -- Lew |
Re: State transition
On 9/21/2012 12:49 PM, Ben Engbers wrote:
> Hi, > > I have problems with my newsreader and can't reply directly but the last > question from Eric Sosman: > > How is the overall program structured? Would you like to > write `if(var.transitioned())' at points of interest, or > would you like to "register an observer" to be notified of > transition events, or would you like transition events to > be queued when they occur and handled later, or what? > > best meets my problem Q: "Do you want X, or Y, or Z, or what?" A: "This question best meets my problem." Consider a career in politics. -- Eric Sosman esosman@ieee-dot-org.invalid |
Re: State transition
Op 21-09-12 19:35, Eric Sosman schreef:
> On 9/21/2012 12:49 PM, Ben Engbers wrote: >> Hi, >> >> I have problems with my newsreader and can't reply directly but the last >> question from Eric Sosman: >> >> How is the overall program structured? Would you like to >> write `if(var.transitioned())' at points of interest, or >> would you like to "register an observer" to be notified of >> transition events, or would you like transition events to >> be queued when they occur and handled later, or what? >> >> best meets my problem > > Q: "Do you want X, or Y, or Z, or what?" > > A: "This question best meets my problem." > > Consider a career in politics. > On 9/21/2012 5:30 PM, Ben Engbers wrote: > I'm sorry for the irritation but while trying to answer to earlier > replys from you and John Matthews, I ran into problems with Thunderbird > (replys to the newsgroup were rejected but why?...) Thunderbird has two buttons for responding to Usenet posts: The button labelled "Reply" (in the English user interface) sends E-mail to the post's author, while "Followup" posts a message to the newsgroup thread. I think a recent Thunderbird update must have rearranged the buttons something, because in the past week or so I've accidentally pressed the wrong one several times! <Ben> I'm glad that I'm not the only one!!! > Your last question was if I wanted transition events to be queued so > that I could handle them later and thats exactly what I want. > > In a simulation I have to consider the possibility that a condition, > based on the value of a variable, is suddenly met and it is only at that > tansition-moment that I want to handle an event. > The value of the variable is determined in a loop and it can also happen > that in the same iteration another condition is also met and that is why > I want to que the events. This still isn't clear. You say you want to handle an event "at that transition-moment," but you also say you want to queue the events and (presumably) handle them later. If you want to respond immediately, you could use a class that wraps the value and its threshold, and whose value-changing method returns a boolean to indicate whether a transition occurred. Then, whenever you store a new value, you'd have something like if (var.setValue(newValue)) { // Transition occurred when newValue was stored. doSomething(); } else { // Stored newValue, no transition. doSomethingElse(); } If you want to queue the event for later handling, you'll need an object to represent the event itself, and a queue (or other collection) that can hold such objects. The setValue() method would detect the transition and add a TransitionEvent object to the queue, and the overall program would run in a loop like Queue<TransitionEvent> queue = new LinkedList<TransitionEvent>(); while (running) { var1.setValue(42); // may add TransitionEvents ... var2.setValue(18); // ... to the queue. ... // Now check the queue for any TransitionEvents. for (TransitionEvent te; (te = queue.poll()) != null; ) { doSomethingWithEvent(te); // or maybe te.doSomething(); your choice } // All events have been handled; ready for next cycle. } > Ben > PS, English is not my native language and although I'm interested in politics only the thought of going into politics scares me! Your English is much better than my Dutch! However, let's move the discussion back to the newsgroup, where other people can see it and offer their advice, too. -- Eric Sosman <Ben> I'll try to implement it by using your Queue<TransitionEvent> queue strategy. Thanks (also the others) and I've learned some interesting things, Ben |
| All times are GMT. The time now is 11:13 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.