Event Dispatcher  v0.1.6-beta.1
Project that offers a small library that allows to subscribe and fire events.
PersonObject.java
Go to the documentation of this file.
1 package com.fermod.testdata.serializable;
2 
3 import java.io.Serializable;
4 import java.util.function.BiConsumer;
5 
7 
8 public class PersonObject implements Serializable {
9 
11  private int age;
12 
13  public PersonObject(String name, int age) {
14  this.observedName = new ObservedValue<>(name);
15  this.age = age;
16  }
17 
18  public String getName() {
19  return observedName.get();
20  }
21 
22  public void setName(String name) {
23  observedName.set(name);
24  }
25 
26  public void onNameChanged(BiConsumer<String, String> consumer) {
27  observedName.registerListener(consumer::accept);
28 
29  /* Equivalent to:
30  observedName.registerListener((oldValue, newValue) -> consumer.accept(oldValue, newValue));
31  */
32 
33  }
34 
35  public int getAge() {
36  return age;
37  }
38 
39  public void setAge(int age) {
40  this.age = age;
41  }
42 
43  @Override
44  public boolean equals(Object obj) {
45 
46  if (obj == null) {
47  return false;
48  }
49 
50  if (!PersonObject.class.isAssignableFrom(obj.getClass())) {
51  return false;
52  }
53 
54  final PersonObject other = (PersonObject) obj;
55  if ((this.observedName == null) ? (other.observedName != null) : !this.observedName.equals(other.observedName)) {
56  return false;
57  }
58 
59  if (this.age != other.age) {
60  return false;
61  }
62 
63  return true;
64  }
65 
66  @Override
67  public int hashCode() {
68  int hash = 3;
69  hash = 53 * hash + (this.observedName != null ? this.observedName.hashCode() : 0);
70  hash = 53 * hash + this.age;
71  return hash;
72  }
73 
74  private static final long serialVersionUID = -8858049414160214232L;
75 
76 }
Class that wraps a value and gives the utility of registering listeners that will be called after any...
void onNameChanged(BiConsumer< String, String > consumer)
void set(T value)
Changes the value with the new given one, and notifies all the registered listeners of the change.
T get()
Returns the value that is being observed.