diff options
Diffstat (limited to 'dicore3/core/src/main/java/io/dico/dicore/event/ChainedListeners.java')
-rw-r--r-- | dicore3/core/src/main/java/io/dico/dicore/event/ChainedListeners.java | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/dicore3/core/src/main/java/io/dico/dicore/event/ChainedListeners.java b/dicore3/core/src/main/java/io/dico/dicore/event/ChainedListeners.java index 1d2bcd4..44050a2 100644 --- a/dicore3/core/src/main/java/io/dico/dicore/event/ChainedListeners.java +++ b/dicore3/core/src/main/java/io/dico/dicore/event/ChainedListeners.java @@ -1,56 +1,56 @@ -package io.dico.dicore.event; - -@SuppressWarnings("unchecked") -public class ChainedListeners { - - private static final ChainedListener<?> empty = new ChainedListener<Object>() { - @Override - public void accept(Object event) { - - } - - @Override - public ChainedListener<Object> withElement(SimpleListener other) { - return ChainedListeners.singleton(other); - } - - @Override - public int getElementCount() { - return 0; - } - - @Override - public SimpleListener<Object> getDelegateOfLastNode() { - return null; - } - }; - - private ChainedListeners() { - - } - - public static <T> ChainedListener<T> empty() { - return (ChainedListener<T>) empty; - } - - public static <T> ChainedListener<T> singleton(SimpleListener<T> element) { - if (element instanceof ChainedListener) { - return (ChainedListener<T>) element; - } - if (element == null) { - return empty(); - } - return new ChainedListener<T>() { - @Override - public void accept(T event) { - element.accept(event); - } - - @Override - public SimpleListener getDelegateOfLastNode() { - return element; - } - }; - } - -} +package io.dico.dicore.event;
+
+@SuppressWarnings("unchecked")
+public class ChainedListeners {
+
+ private static final ChainedListener<?> empty = new ChainedListener<Object>() {
+ @Override
+ public void accept(Object event) {
+
+ }
+
+ @Override
+ public ChainedListener<Object> withElement(SimpleListener other) {
+ return ChainedListeners.singleton(other);
+ }
+
+ @Override
+ public int getElementCount() {
+ return 0;
+ }
+
+ @Override
+ public SimpleListener<Object> getDelegateOfLastNode() {
+ return null;
+ }
+ };
+
+ private ChainedListeners() {
+
+ }
+
+ public static <T> ChainedListener<T> empty() {
+ return (ChainedListener<T>) empty;
+ }
+
+ public static <T> ChainedListener<T> singleton(SimpleListener<T> element) {
+ if (element instanceof ChainedListener) {
+ return (ChainedListener<T>) element;
+ }
+ if (element == null) {
+ return empty();
+ }
+ return new ChainedListener<T>() {
+ @Override
+ public void accept(T event) {
+ element.accept(event);
+ }
+
+ @Override
+ public SimpleListener getDelegateOfLastNode() {
+ return element;
+ }
+ };
+ }
+
+}
|