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

xapi.util.impl.ReceivesMultiValue Maven / Gradle / Ivy

Go to download

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

The newest version!
package xapi.util.impl;

import xapi.collect.api.Fifo;
import xapi.collect.impl.SimpleFifo;
import xapi.util.api.ReceivesValue;

/**
 * An object designed to delegate a received value to multiple ReceivesValue callbacks.
 *
 * 

* * Fires callbacks based on insertion order.
* If you need more control of firing order, use {@link ReceivesPrioritizedValue} instead. * * @author James X. Nelson ([email protected], @james) * * @param - The type of object / event / signal being sent. */ public class ReceivesMultiValue implements ReceivesValue{ /** A simple array of callbacks to fire. Uses low-level js arrays in gwt.*/ final Fifo> handlers = new SimpleFifo>(); public void set(T value) { while(!handlers.isEmpty()){ handlers.take().set(value); } }; /** * Adds a receiver to the end of the callback array. * * @param receiver - A new receiver to add * @return true if the receiver was added to our callbacks; false if already present. */ public boolean addReceiver(ReceivesValue receiver){ assert receiver != null : "Do not send null receivers to "+this+"; (ReceivesMultiValue) "; assert receiver != this : "Do not send a ReceivesMultiValue to itself. Class: "+this+";"; if (handlers.contains(receiver)) return false; handlers.give(receiver); return true; } /** * Clear our array of callbacks */ public void clearReceivers(){ handlers.clear(); } /** * @param receiver - The receiver to remove. */ public void removeReceiver(ReceivesValue receiver){ handlers.remove(receiver); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy