All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.edgar615.util.eventbus.HandlerRegistration Maven / Gradle / Ivy

There is a newer version: 1.0.11
Show newest version
package com.github.edgar615.util.eventbus;

import com.github.edgar615.util.event.Event;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.stream.Collectors;

/**
 * Created by Edgar on 2017/4/14.
 *
 * @author Edgar  Date 2017/4/14
 */
public class HandlerRegistration {
  private static final HandlerRegistration INSTANCE = new HandlerRegistration();

  private final List bindings = new ArrayList<>();

  private HandlerRegistration() {
  }

  public static HandlerRegistration instance() {
    return INSTANCE;
  }

  public void registerHandler(BiPredicate predicate, EventHandler handler) {
    HandlerBinding binding = new HandlerBinding(predicate, handler);
    bindings.add(binding);
  }

  public List getHandlers(Event event) {
    return bindings.stream()
            .filter(b -> b.match(event))
            .map(b -> b.eventHandler())
            .collect(Collectors.toList());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy