Op 21-09-12 19:35, Eric Sosman schreef:
Q: "Do you want X, or Y, or Z, or what?"
A: "This question best meets my problem."
Consider a career in politics.
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!
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