Class Ribbon<T>

  • Type Parameters:
    T -
    All Implemented Interfaces:
    Consumer<T>, Supplier<T>

    public class Ribbon<T>
    extends Object
    implements Supplier<T>, Consumer<T>

    A Ribbon connects a data object of type T with a supplier and a consumer. A client of the ribbon can read the data object via the supplier and write or replace the data object via the supplier.

    Example:

       java.awt.Point p= new java.awt.Point(4,5);
       Ribbon rx= new Ribbon<>(() -> p.x, newx -> p.x= newx);
     

    The previous example allows a client to read and replace the x coordinate of p, without knowing about the type of the whole object p.

    The name "ribbon" comes from looking at it as a thing that is start and ending in itself, just like a printer ribbon.