State transition

Discussion in 'Java' started by Ben Engbers, Sep 21, 2012.

  1. Ben Engbers

    Ben Engbers Guest

    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
    Ben Engbers, Sep 21, 2012
    #1
    1. Advertising

  2. Ben Engbers

    Lew Guest

    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
    Lew, Sep 21, 2012
    #2
    1. Advertising

  3. Ben Engbers

    Eric Sosman Guest

    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
    d
    Eric Sosman, Sep 21, 2012
    #3
  4. Ben Engbers

    Ben Engbers Guest

    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
    Ben Engbers, Sep 21, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Divyang M
    Replies:
    9
    Views:
    608
    Divyang M
    May 18, 2005
  2. Divyang M
    Replies:
    1
    Views:
    556
    Jerzy Gbur
    May 15, 2005
  3. hari_krishna

    FSM State transition coverage

    hari_krishna, Aug 22, 2006, in forum: VHDL
    Replies:
    0
    Views:
    925
    hari_krishna
    Aug 22, 2006
  4. Robert Winsor

    Sub-bit transition state?

    Robert Winsor, Oct 28, 2006, in forum: VHDL
    Replies:
    1
    Views:
    462
    Robert Winsor
    Oct 28, 2006
  5. Ben Engbers
    Replies:
    4
    Views:
    324
    Daniele Futtorovic
    Sep 21, 2012
Loading...

Share This Page