mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 19:49:11 +03:00
29 lines
635 B
Java
29 lines
635 B
Java
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>
|
|
{
|
|
boolean hook(R context) throws HookException;
|
|
}
|
|
public void registerHook(Hook<R> hook)
|
|
{
|
|
list.add(hook);
|
|
}
|
|
public boolean unregisterHook(Hook<R> hook)
|
|
{
|
|
return list.remove(hook);
|
|
}
|
|
public boolean hook(R context) throws HookException
|
|
{
|
|
for(Hook<R> hook : list)
|
|
{
|
|
if(hook.hook(context)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|