mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] BiHookSet
This commit is contained in:
parent
886524bb94
commit
6ec3211450
1 changed files with 29 additions and 0 deletions
29
libLauncher/src/main/java/ru/gravit/utils/BiHookSet.java
Normal file
29
libLauncher/src/main/java/ru/gravit/utils/BiHookSet.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package ru.gravit.utils;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class BiHookSet<V,R> {
|
||||||
|
public Set<Hook<V,R>> list = new HashSet<>();
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface Hook<V, R>
|
||||||
|
{
|
||||||
|
boolean hook(V object, R context);
|
||||||
|
}
|
||||||
|
public void registerHook(Hook<V, R> hook)
|
||||||
|
{
|
||||||
|
list.add(hook);
|
||||||
|
}
|
||||||
|
public boolean unregisterHook(Hook<V, R> hook)
|
||||||
|
{
|
||||||
|
return list.remove(hook);
|
||||||
|
}
|
||||||
|
public boolean hook(V object, R context)
|
||||||
|
{
|
||||||
|
for(Hook<V, R> hook : list)
|
||||||
|
{
|
||||||
|
if(hook.hook(object, context)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue