[FEATURE] BiHookSet

This commit is contained in:
Gravit 2019-05-03 21:14:03 +07:00
parent 886524bb94
commit 6ec3211450
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View 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;
}
}