mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 19:49:11 +03:00
28 lines
665 B
Java
28 lines
665 B
Java
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) throws HookException;
|
|
}
|
|
|
|
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 context, R object) throws HookException {
|
|
for (Hook<V, R> hook : list) {
|
|
if (hook.hook(context, object)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|