-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dedicated classes for listener manager
- Loading branch information
Showing
7 changed files
with
96 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
core/src/main/java/me/hsgamer/topper/core/listener/EntryListenerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package me.hsgamer.topper.core.listener; | ||
|
||
import me.hsgamer.topper.core.entry.DataEntry; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public class EntryListenerManager<T> { | ||
private final List<Consumer<DataEntry<T>>> listeners = new ArrayList<>(); | ||
|
||
public void add(Consumer<DataEntry<T>> listener) { | ||
listeners.add(listener); | ||
} | ||
|
||
public void remove(Consumer<DataEntry<T>> listener) { | ||
listeners.remove(listener); | ||
} | ||
|
||
public void clear() { | ||
listeners.clear(); | ||
} | ||
|
||
public void notifyListeners(DataEntry<T> entry) { | ||
listeners.forEach(listener -> listener.accept(entry)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
core/src/main/java/me/hsgamer/topper/core/listener/ListenerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package me.hsgamer.topper.core.listener; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ListenerManager { | ||
private final List<Runnable> listeners = new ArrayList<>(); | ||
|
||
public void add(Runnable listener) { | ||
listeners.add(listener); | ||
} | ||
|
||
public void remove(Runnable listener) { | ||
listeners.remove(listener); | ||
} | ||
|
||
public void clear() { | ||
listeners.clear(); | ||
} | ||
|
||
public void notifyListeners() { | ||
listeners.forEach(Runnable::run); | ||
} | ||
} |