Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #18891

Re: Best strategy to follow a state transition?

From Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Best strategy to follow a state transition?
Date 2012-09-22 00:08 +0200
Organization A noiseless patient Spider
Message-ID <k3ioh9$a21$1@dont-email.me> (permalink)
References <505c4afc$0$6941$e4fe514c@news2.news.xs4all.nl>

Show all headers | View raw


On 21/09/2012 13:09, Ben Engbers allegedly wrote:
> Hi,
> 
> In my program, I know that at some moment the value of a variable X will
> change from value 1 to value 2. I am not interested in the value of X
> itself but the transition should trigger an event. Example, if the value
> of a stock will reach a certain value, I want to sell but after that I'm
> not interested in the value anymore (until it might reach another
> break-value).
> 
> Of course I could program this as:
> if oldvalue <= testvalue and newvalue > testvalue then
>   do something;
>   oldvalue = newvalue;
> end
> But suppose that there are a lot of variables that I need to watch and I
> don't want to write a test for every one.
> 
> Wat is the best strategy to watch the transition?
> 
> Ben

Listeners.

<http://docs.oracle.com/javase/tutorial/uiswing/events/changelistener.html>

See also the (somewhat older)
<http://docs.oracle.com/javase/7/docs/api/java/util/Observable.html>.

-- 
DF.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Best strategy to follow a state transition? Ben Engbers <Ben.dot.Engbers@Be-Logical.dot.nl> - 2012-09-21 13:09 +0200
  Re: Best strategy to follow a state transition? "John B. Matthews" <nospam@nospam.invalid> - 2012-09-21 07:36 -0400
  Re: Best strategy to follow a state transition? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-21 09:51 -0400
    Re: Best strategy to follow a state transition? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-09-21 10:26 -0700
  Re: Best strategy to follow a state transition? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-09-22 00:08 +0200

csiph-web