Event Dispatcher  v0.1.6-beta.1
Project that offers a small library that allows to subscribe and fire events.
ObservedValue< T >

Detailed Description

Class that wraps a value and gives the utility of registering listeners that will be called after any variable value change.

Parameters
<T>the type of the observed value

Definition at line 17 of file ObservedValue.java.

+ Inheritance diagram for ObservedValue< T >:

Public Member Functions

 ObservedValue (T value)
 
void set (T value)
 
void set (T value, boolean notifyChange)
 
get ()
 
boolean equals (Object obj)
 
int hashCode ()
 
- Public Member Functions inherited from EventPublisher< T >
registerListener (T listener)
 
void unregisterListener (T listener)
 
void unregisterAllListeners ()
 
void notifyListeners (Consumer<? super T > action)
 

Private Member Functions

void writeObject (ObjectOutputStream out) throws IOException
 
void readObject (ObjectInputStream in) throws IOException, ClassNotFoundException
 

Private Attributes

value
 

Static Private Attributes

static final long serialVersionUID = 8159940159964193507L
 

Additional Inherited Members

- Protected Attributes inherited from EventPublisher< T >
final Lock readLock = readWriteLock.readLock()
 
final Lock writeLock = readWriteLock.writeLock()
 

Constructor & Destructor Documentation

◆ ObservedValue()

ObservedValue ( value)

Constructor of the class.

ObservedValue<T>

that takes as parameter the value that will be initialized the observed value.

Parameters
valuethe value that will be initialized to

Definition at line 27 of file ObservedValue.java.

Member Function Documentation

◆ set() [1/2]

void set ( value)

Changes the value with the new given one, and notifies all the registered listeners of the change.

Parameters
valuethe new value to assign

Definition at line 37 of file ObservedValue.java.

◆ set() [2/2]

void set ( value,
boolean  notifyChange 
)

Changes the value with the new given one, and depending if the notification on change is enabled or not it will notify all the registered listeners.

Parameters
valuethe new value to assign
notifyChange

Definition at line 49 of file ObservedValue.java.

◆ get()

T get ( )

Returns the value that is being observed.

Returns
the value

Definition at line 66 of file ObservedValue.java.

◆ equals()

boolean equals ( Object  obj)

Definition at line 71 of file ObservedValue.java.

◆ hashCode()

int hashCode ( )

Definition at line 91 of file ObservedValue.java.

◆ writeObject()

void writeObject ( ObjectOutputStream  out) throws IOException
private

The writeObject method is responsible for writing the state of the object for its particular class so that the corresponding readObject method can restore it.

It may call the default mechanism for saving the Object's fields calling out.defaultWriteObject.

The method does not need to concern itself with the state belonging to its superclasses or subclasses. State is saved by writing the individual fields to the ObjectOutputStream using the writeObject method or by using the methods for primitive data types supported by DataOutput.

Parameters
outwrites primitive data types and graphs of Java objects to an OutputStream
Exceptions
IOExceptionthrown when an I/O exception of some sort has occurred
See also
Serializable
ObjectOutputStream

Definition at line 115 of file ObservedValue.java.

◆ readObject()

void readObject ( ObjectInputStream  in) throws IOException, ClassNotFoundException
private

The readObject method is responsible for reading from the stream and restoring the classes fields.

It may call in.defaultReadObject to invoke the default mechanism for restoring the object's non-static and non-transient fields

The defaultReadObject method uses information in the stream to assign the fields of the object saved in the stream with the correspondingly named fields in the current object.

This method handles the cast when the class has evolved to add new fields. The method does not need to concern itself with the state belonging to its superclasses or subclasses. State is saved by writing the individual fields to the ObjectOutputStream using the writeObject method or by using the methods for primitive data types supported by DataOutput.

Parameters
inthe ObjectInputStream that deserializes primitive data and objects previously written using an ObjectOutputStream
Exceptions
IOExceptionthrown when an I/O exception of some sort has occurred
ClassNotFoundExceptionthrown when an application does not found a definition for the class with the specified name
See also
Serializable
ObjectInputStream

Definition at line 145 of file ObservedValue.java.

Member Data Documentation

◆ value

T value
private

Definition at line 19 of file ObservedValue.java.

◆ serialVersionUID

final long serialVersionUID = 8159940159964193507L
staticprivate

Auto-generated serial version ID.

Definition at line 152 of file ObservedValue.java.