|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcz.cuni.utils.Flag<T>
T
- type of the flagpublic class Flag<T>
This is flag class which is designed for Boolean or Integer types (but it should work with other types as well as long as they have equals() implemented correctly. It allows you to store the state of flag and register listeners on the flag. I've design it because of Threads which communicates over sockets. I'm using two boolean flags -> threadIsRunning (which is set at the beginning of run() and at the end of it) and communicationAlive ... usually communication can be dropped or thread exits (due to exception for instance) and you need to take some actions because of it. Check out FlagListener interface documentation too!
Nested Class Summary | |
---|---|
(package private) class |
Flag.ListenerStore<T>
|
Field Summary | |
---|---|
protected ImmutableFlag<T> |
immutableWrapper
Immutable version of this flag. |
private java.util.ArrayList<Flag.ListenerStore<T>> |
listeners
|
private T |
value
|
Constructor Summary | |
---|---|
Flag()
Initialize the flag with 'initialValue'. |
|
Flag(T initialValue)
Initialize the flag with 'initialValue'. |
Method Summary | |
---|---|
boolean |
addListener(FlagListener<T> listener)
Adds new listener to the flag. |
boolean |
addListener(FlagListener<T> listener,
int callListenerWithParam)
Adds new listener to the flag with specified param. |
void |
clearListeners()
Call to clear (remove) all the listeners on the flag. |
T |
getFlag()
Returns the value of the flag. |
ImmutableFlag<T> |
getImmutable()
|
boolean |
isListenning(FlagListener<T> listener)
Checks whether listener is already registered (with any parameter). |
boolean |
isListenning(FlagListener<T> listener,
int listenerParam)
Checks whether listener is already registered (with specified parameter). |
static void |
main(java.lang.String[] args)
Not so good test of the flag - you need to confirm the results for yourself. |
boolean |
removeListener(FlagListener<T> listener)
Removes all registered 'listener' from the flag (doesn't depend on the parameter, all listeners are removed). |
boolean |
removeListener(FlagListener<T> listener,
int listenerParam)
Removes all registered 'listener' from the flag (with specified listenerParam). |
void |
setFlag(T newValue)
Changes the flag and informs all listeners. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private T value
private java.util.ArrayList<Flag.ListenerStore<T>> listeners
protected ImmutableFlag<T> immutableWrapper
Constructor Detail |
---|
public Flag()
public Flag(T initialValue)
initialValue
- Method Detail |
---|
public void setFlag(T newValue)
newValue
- public ImmutableFlag<T> getImmutable()
public T getFlag()
public boolean addListener(FlagListener<T> listener, int callListenerWithParam)
listener
- public boolean addListener(FlagListener<T> listener)
listener
- public boolean removeListener(FlagListener<T> listener)
listener
-
public boolean removeListener(FlagListener<T> listener, int listenerParam)
listener
-
public boolean isListenning(FlagListener<T> listener)
listener
-
public boolean isListenning(FlagListener<T> listener, int listenerParam)
listener
-
public void clearListeners()
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |