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

net.sf.javagimmicks.util8.WritableSupplier Maven / Gradle / Ivy

There is a newer version: 0.99-alpha1
Show newest version
package net.sf.javagimmicks.util8;

import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * This interface extends {@link Supplier} by providing additional methods that
 * allow write access to the contained object.
 * 
 * @param 
 *           the type of object the container can carry
 */
public interface WritableSupplier extends Supplier, Consumer
{
   /**
    * Returns if an already set object instance may be replaced by another one
    * 
    * @return if an already set object instance my be replaced by another one
    * @see #accept(Object)
    */
   boolean isAllowOverwrite();

   /**
    * Registers an instance in the container
    * 
    * @param instance
    *           the instance to register
    * @throws IllegalStateException
    *            if the given instances is not null and there is
    *            already another instance registered and
    *            {@link #isAllowOverwrite()} is true
    * @see #isAllowOverwrite()
    */
   void accept(E instance) throws IllegalStateException;

   /**
    * Removes the instance (if any) from the container
    * 
    * @return the previously registered instance or null if none
    *         was registered
    */
   E remove();

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy