Search in sources :

Example 1 with DblSource

use of suite.primitive.DblPrimitives.DblSource in project suite by stupidsing.

the class DblFunUtil method suck.

/**
 * Sucks data from a sink and produce into a source.
 */
public static DblSource suck(Sink<DblSink> fun) {
    NullableSyncQueue<Double> queue = new NullableSyncQueue<>();
    DblSink enqueue = c -> enqueue(queue, c);
    Thread thread = Thread_.startThread(() -> {
        try {
            fun.sink(enqueue);
        } finally {
            enqueue(queue, EMPTYVALUE);
        }
    });
    return () -> {
        try {
            return queue.take();
        } catch (InterruptedException ex) {
            thread.interrupt();
            return Fail.t(ex);
        }
    };
}
Also used : DblSink(suite.primitive.DblPrimitives.DblSink) DblSource(suite.primitive.DblPrimitives.DblSource) Dbl_Obj(suite.primitive.DblPrimitives.Dbl_Obj) Iterator(java.util.Iterator) LogUtil(suite.os.LogUtil) Source2(suite.util.FunUtil2.Source2) Source(suite.util.FunUtil.Source) NullableSyncQueue(suite.util.NullableSyncQueue) Thread_(suite.util.Thread_) Fun(suite.util.FunUtil.Fun) DblObjSource(suite.primitive.DblPrimitives.DblObjSource) Sink(suite.util.FunUtil.Sink) Collections(java.util.Collections) Fail(suite.util.Fail) DblTest(suite.primitive.DblPrimitives.DblTest) DblObjPair(suite.primitive.adt.pair.DblObjPair) NullableSyncQueue(suite.util.NullableSyncQueue) DblSink(suite.primitive.DblPrimitives.DblSink)

Example 2 with DblSource

use of suite.primitive.DblPrimitives.DblSource in project suite by stupidsing.

the class DblSet method forEach.

public void forEach(DblSink sink) {
    DblSource source = source_();
    double c;
    while ((c = source.source()) != DblFunUtil.EMPTYVALUE) sink.sink(c);
}
Also used : DblSource(suite.primitive.DblPrimitives.DblSource)

Example 3 with DblSource

use of suite.primitive.DblPrimitives.DblSource in project suite by stupidsing.

the class DblOutlet method equals.

@Override
public boolean equals(Object object) {
    if (Object_.clazz(object) == DblOutlet.class) {
        DblSource source1 = ((DblOutlet) object).source;
        double o0, o1;
        while (Objects.equals(o0 = source.source(), o1 = source1.source())) if (o0 == DblFunUtil.EMPTYVALUE && o1 == DblFunUtil.EMPTYVALUE)
            return true;
        return false;
    } else
        return false;
}
Also used : DblSource(suite.primitive.DblPrimitives.DblSource)

Aggregations

DblSource (suite.primitive.DblPrimitives.DblSource)3 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 LogUtil (suite.os.LogUtil)1 DblObjSource (suite.primitive.DblPrimitives.DblObjSource)1 DblSink (suite.primitive.DblPrimitives.DblSink)1 DblTest (suite.primitive.DblPrimitives.DblTest)1 Dbl_Obj (suite.primitive.DblPrimitives.Dbl_Obj)1 DblObjPair (suite.primitive.adt.pair.DblObjPair)1 Fail (suite.util.Fail)1 Fun (suite.util.FunUtil.Fun)1 Sink (suite.util.FunUtil.Sink)1 Source (suite.util.FunUtil.Source)1 Source2 (suite.util.FunUtil2.Source2)1 NullableSyncQueue (suite.util.NullableSyncQueue)1 Thread_ (suite.util.Thread_)1