T
- the type of the publisherU
- the type of the optional data argumentpublic final class Subscriptions<T,U> extends java.lang.Object
Subscriber
Constructor and Description |
---|
Subscriptions(T publisher)
Initializes a new instance of the
Subscriptions class with
zero subscribers. |
Modifier and Type | Method and Description |
---|---|
void |
addSubscriber(Subscriber<T,U> subscriber)
Adds an subscriber to the set of subscribers for the publisher object,
provided that it is not the same as some subscriber already in the set.
|
void |
clearChanged()
Indicates that the publisher object has no longer changed, or that it has
already notified all of its subscribers of its most recent change, so that
hasChanged() will now return false . |
int |
countSubscribers()
Returns the number of subscribers of publisher object.
|
void |
deleteSubscriber(Subscriber<T,U> subscriber)
Deletes an subscriber from the set of subscribers.
|
void |
deleteSubscribers()
Clears the subscriber list so that the publisher object no longer has any
subscribers.
|
boolean |
hasChanged()
Returns
true if the publisher object has changed;
otherwise, false . |
void |
notifySubscribers()
If this object has changed, as indicated by the
hasChanged() ,
then notify all of its subscribers and then clear the changed state. |
void |
notifySubscribers(U data)
If this object has changed, as indicated by the
hasChanged() ,
then notify all of its subscribers and then clear the changed state. |
void |
setChanged()
Flags the publisher object as having changed.
|
public Subscriptions(T publisher)
Subscriptions
class with
zero subscribers.publisher
- the object being publisherjava.lang.IllegalArgumentException
- if publisher is null
public void addSubscriber(Subscriber<T,U> subscriber)
subscriber
- java.lang.IllegalArgumentException
- if the parameter subscriber is null
public void clearChanged()
hasChanged()
will now return false
. This method
is called automatically by the notifySubscribers()
methods.public int countSubscribers()
public void deleteSubscriber(Subscriber<T,U> subscriber)
null
to this method will have no effect.subscriber
- the Subscriber
to be deletedpublic void deleteSubscribers()
public boolean hasChanged()
true
if the publisher object has changed;
otherwise, false
.true
if the publisher object has changed;
otherwise, false
public void notifySubscribers()
hasChanged()
,
then notify all of its subscribers and then clear the changed state. This
method is equivalent to calling notifySubscribers(null)
.public void notifySubscribers(U data)
hasChanged()
,
then notify all of its subscribers and then clear the changed state.data
- optional event specific data which will be passed to the subscriberspublic void setChanged()