cz.cuni.amis.utils.flag
Class ReasonFlag<TYPE,REASON>

Package class diagram package ReasonFlag
java.lang.Object
  extended by cz.cuni.amis.utils.flag.Flag<TYPE>
      extended by cz.cuni.amis.utils.flag.ReasonFlag<TYPE,REASON>
Type Parameters:
TYPE -
REASON -
All Implemented Interfaces:
IFlag<TYPE>, IReasonFlag<TYPE,REASON>, Serializable

public class ReasonFlag<TYPE,REASON>
extends Flag<TYPE>
implements IReasonFlag<TYPE,REASON>, Serializable

Allows you to pass reasons of flag change along with new value of the flag.

This extension of Flag is MAGICAL! And I mean it ... it is correct from the point of view of OOP (asfaik), but the Flag alone is complex class and we're trying to hack another parameter to the setFlag() method!

Anyway, it works as you would expect it to work ;)

Author:
Jimmy
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class cz.cuni.amis.utils.flag.Flag
Flag.DoInSync<T>
 
Constructor Summary
ReasonFlag()
          Initialize the flag without 'initialValue', initial value will be null.
ReasonFlag(TYPE initialValue)
          Initialize the flag with 'initialValue'.
 
Method Summary
 void addListener(FlagListener<TYPE> listener)
          Use ReasonFlagListener to get reasons or simple FlagListener to only receives new values.
 void addStrongListener(FlagListener<TYPE> listener)
          Use ReasonFlagListener to get reasons or simple FlagListener to only receives new values.
 ImmutableReasonFlag<TYPE,REASON> getImmutable()
           
static void main(String[] args)
          TEST METHOD!
 void setFlag(TYPE newValue, REASON reasonForChange)
          Changes the flag and informs all listeners.
 
Methods inherited from class cz.cuni.amis.utils.flag.Flag
clearListeners, defreeze, freeze, getFlag, inSync, inSyncInner, isFrozen, isListenning, isNone, isOne, removeAllListeners, removeListener, setFlag, waitFor, waitFor, waitForChange, waitForChange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.amis.utils.flag.IFlag
clearListeners, defreeze, freeze, getFlag, inSync, isFrozen, isListenning, removeAllListeners, removeListener, setFlag
 

Constructor Detail

ReasonFlag

public ReasonFlag()
Initialize the flag without 'initialValue', initial value will be null.


ReasonFlag

public ReasonFlag(TYPE initialValue)
Initialize the flag with 'initialValue'.

Parameters:
initialValue -
Method Detail

setFlag

public void setFlag(TYPE newValue,
                    REASON reasonForChange)
Changes the flag and informs all listeners.

Should not produce any dead-locks even though it is synchronized method.

Specified by:
setFlag in interface IReasonFlag<TYPE,REASON>
Parameters:
newValue -
Throws:
InterruptedRuntimeException - if interrupted during the await on the freeze latch

addStrongListener

public void addStrongListener(FlagListener<TYPE> listener)
Use ReasonFlagListener to get reasons or simple FlagListener to only receives new values.

FlagListener will be wrapped using ReasonFlagListener.FlagListenerAdapter

For more documentation see Flag

Specified by:
addStrongListener in interface IFlag<TYPE>
Overrides:
addStrongListener in class Flag<TYPE>
Parameters:
listener -

addListener

public void addListener(FlagListener<TYPE> listener)
Use ReasonFlagListener to get reasons or simple FlagListener to only receives new values.

FlagListener will be wrapped using ReasonFlagListener.FlagListenerAdapter

For more documentation see Flag.

WARNING:The listener is stored via weak-reference!

Specified by:
addListener in interface IFlag<TYPE>
Overrides:
addListener in class Flag<TYPE>
Parameters:
listener -

main

public static void main(String[] args)
TEST METHOD!

Test by eye :-(


getImmutable

public ImmutableReasonFlag<TYPE,REASON> getImmutable()
Specified by:
getImmutable in interface IFlag<TYPE>
Overrides:
getImmutable in class Flag<TYPE>
Returns:
Immutable version of this flag, setFlag(T) method of such a flag will raise an exception.


Copyright © 2015 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.