From 6ec32114503aee7918502b2b2bd211ced8cc9450 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 3 May 2019 21:14:03 +0700 Subject: [PATCH] [FEATURE] BiHookSet --- .../main/java/ru/gravit/utils/BiHookSet.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 libLauncher/src/main/java/ru/gravit/utils/BiHookSet.java diff --git a/libLauncher/src/main/java/ru/gravit/utils/BiHookSet.java b/libLauncher/src/main/java/ru/gravit/utils/BiHookSet.java new file mode 100644 index 00000000..9e20c4a2 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/utils/BiHookSet.java @@ -0,0 +1,29 @@ +package ru.gravit.utils; + +import java.util.HashSet; +import java.util.Set; + +public class BiHookSet { + public Set> list = new HashSet<>(); + @FunctionalInterface + public interface Hook + { + boolean hook(V object, R context); + } + public void registerHook(Hook hook) + { + list.add(hook); + } + public boolean unregisterHook(Hook hook) + { + return list.remove(hook); + } + public boolean hook(V object, R context) + { + for(Hook hook : list) + { + if(hook.hook(object, context)) return true; + } + return false; + } +}