Event Dispatcher  v0.1.6-beta.1
Project that offers a small library that allows to subscribe and fire events.
Examples.java
Go to the documentation of this file.
1 package com.fermod.example;
2 
5 
6 public class Examples {
7 
8  public static void main(String[] args) {
9 
10  ObservedValue<Integer> observedValue = new ObservedValue<>(0);
11 
12  // Inline listener registration using lambda
13  observedValue.registerListener((oldVAlue, newValue) -> {
14  System.out.println("Executed lambda inline code. Old value: " + oldVAlue + " New value: " + newValue);
15  });
16 
17  // Equivalent inline listener registration of the lambda
19  @Override
20  public void onValueChanged(Integer oldValue, Integer value) {
21  System.out.println("Executed inline code. Old value: " + oldValue + " New value: " + value);
22  }
23  });
24 
25  // Register a mothod using method references
27 
28  System.out.println("Change value to 10");
29  observedValue.set(10);
30 
31  }
32 
33  public static void printValueChange(int oldValue, int newValue) {
34  System.out.println("Executed printValueChange method. Old value: " + oldValue + " New value: " + newValue);
35  }
36 
37 }
Class that wraps a value and gives the utility of registering listeners that will be called after any...
static void printValueChange(int oldValue, int newValue)
Definition: Examples.java:33
static void main(String[] args)
Definition: Examples.java:8
T registerListener(T listener)
Adds the specified listener to the list of registered listeners.
The listener interface for receiving value change events.
void set(T value)
Changes the value with the new given one, and notifies all the registered listeners of the change.