2019-05-03 17:14:03 +03:00
|
|
|
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>
|
|
|
|
{
|
2019-05-03 17:34:10 +03:00
|
|
|
boolean hook(V object, R context) throws HookException;
|
2019-05-03 17:14:03 +03:00
|
|
|
}
|
|
|
|
public void registerHook(Hook<V, R> hook)
|
|
|
|
{
|
|
|
|
list.add(hook);
|
|
|
|
}
|
|
|
|
public boolean unregisterHook(Hook<V, R> hook)
|
|
|
|
{
|
|
|
|
return list.remove(hook);
|
|
|
|
}
|
2019-05-03 17:34:10 +03:00
|
|
|
public boolean hook(V context, R object) throws HookException
|
2019-05-03 17:14:03 +03:00
|
|
|
{
|
|
|
|
for(Hook<V, R> hook : list)
|
|
|
|
{
|
2019-05-03 17:34:10 +03:00
|
|
|
if(hook.hook(context, object)) return true;
|
2019-05-03 17:14:03 +03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|