Launcher/libLauncher/src/main/java/ru/gravit/utils/BiHookSet.java

29 lines
665 B
Java
Raw Normal View History

2019-05-03 17:14:03 +03:00
package ru.gravit.utils;
import java.util.HashSet;
import java.util.Set;
2019-05-15 14:11:22 +03:00
public class BiHookSet<V, R> {
public Set<Hook<V, R>> list = new HashSet<>();
2019-05-03 17:14:03 +03:00
@FunctionalInterface
2019-05-15 14:11:22 +03:00
public interface Hook<V, R> {
boolean hook(V object, R context) throws HookException;
2019-05-03 17:14:03 +03:00
}
2019-05-15 14:11:22 +03:00
public void registerHook(Hook<V, R> hook) {
2019-05-03 17:14:03 +03:00
list.add(hook);
}
2019-05-15 14:11:22 +03:00
public boolean unregisterHook(Hook<V, R> hook) {
2019-05-03 17:14:03 +03:00
return list.remove(hook);
}
2019-05-15 14:11:22 +03:00
public boolean hook(V context, R object) throws HookException {
for (Hook<V, R> hook : list) {
if (hook.hook(context, object)) return true;
2019-05-03 17:14:03 +03:00
}
return false;
}
}