2019-04-24 09:08:22 +03:00
|
|
|
package ru.gravit.utils;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
public class HookSet<R> {
|
|
|
|
public Set<Hook<R>> list = new HashSet<>();
|
|
|
|
@FunctionalInterface
|
|
|
|
public interface Hook<R>
|
|
|
|
{
|
2019-05-03 17:34:10 +03:00
|
|
|
boolean hook(R context) throws HookException;
|
2019-04-24 09:08:22 +03:00
|
|
|
}
|
|
|
|
public void registerHook(Hook<R> hook)
|
|
|
|
{
|
|
|
|
list.add(hook);
|
|
|
|
}
|
|
|
|
public boolean unregisterHook(Hook<R> hook)
|
|
|
|
{
|
|
|
|
return list.remove(hook);
|
|
|
|
}
|
2019-05-03 17:34:10 +03:00
|
|
|
public boolean hook(R context) throws HookException
|
2019-04-24 09:08:22 +03:00
|
|
|
{
|
|
|
|
for(Hook<R> hook : list)
|
|
|
|
{
|
|
|
|
if(hook.hook(context)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|