/*
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.events;

/**
 * This interface represents strategy used to join multiple events into one.
 * The idea of merging events of similiar type is extgensively used inside
 * AWT library and Swing. It allows to avoid unecessary repaints of the same element over
 * and over again, it allows to repaint one big area in one operation, instead of repaint
 * many smaller areas.
 *
 * In other other words: it is usefull everytime, when intermediate steps could be skipped,
 * because onr bulk operation could generate final result expected by consumers.
 *
 * @author ranides
 */
public interface EventJoiner {

    /**
     * This is strategy which does not join anything at all.
     *
     * It simply skips older event, but first, it signals, that events shouldn't be merged.
     */
    EventJoiner NONE = new EventJoiner() {
        @Override
        public boolean isJoinable(Event first, Event second) {
            return false;
        }

        @Override
        public Event join(Event first, Event second) {
            return second;
        }
    };
    
    /**
     * Returns true if two passed events could be merged into one in effective way.
     *
     * @param first first
     * @param second second
     * @return bool
     */
    boolean isJoinable(Event first, Event second);
    
    /**
     * Creates new event, which should create the same final result as processing two events
     * one after another. In other words: it creates bulk operation.
     *
     * @param first first
     * @param second second
     * @return event
     */
    Event join(Event first, Event second);
    
}
