Search in sources :

Example 1 with IntSource

use of suite.primitive.IntPrimitives.IntSource in project suite by stupidsing.

the class IntOutlet method equals.

@Override
public boolean equals(Object object) {
    if (Object_.clazz(object) == IntOutlet.class) {
        IntSource source1 = ((IntOutlet) object).source;
        int o0, o1;
        while (Objects.equals(o0 = source.source(), o1 = source1.source())) if (o0 == IntFunUtil.EMPTYVALUE && o1 == IntFunUtil.EMPTYVALUE)
            return true;
        return false;
    } else
        return false;
}
Also used : IntSource(suite.primitive.IntPrimitives.IntSource)

Example 2 with IntSource

use of suite.primitive.IntPrimitives.IntSource in project suite by stupidsing.

the class IntSet method forEach.

public void forEach(IntSink sink) {
    IntSource source = source_();
    int c;
    while ((c = source.source()) != IntFunUtil.EMPTYVALUE) sink.sink(c);
}
Also used : IntSource(suite.primitive.IntPrimitives.IntSource)

Example 3 with IntSource

use of suite.primitive.IntPrimitives.IntSource in project suite by stupidsing.

the class RunUtil method run.

public static void run(Class<? extends ExecutableProgram> clazz, String[] args, RunOption runOption) {
    LogUtil.initLog4j(Level.INFO);
    IntMutable mutableCode = IntMutable.nil();
    IntSource source = () -> {
        try {
            try (ExecutableProgram main_ = Object_.new_(clazz)) {
                return main_.run(args) ? 0 : 1;
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
            LogUtil.fatal(ex);
            return 2;
        }
    };
    Runnable runnable = () -> mutableCode.set(source.source());
    switch(runOption) {
        case PROFILE:
            new Profiler().profile(runnable);
            break;
        case RUN____:
            runnable.run();
            break;
        case TIME___:
            LogUtil.duration(clazz.getSimpleName(), () -> {
                runnable.run();
                return Boolean.TRUE;
            });
    }
    int code = mutableCode.get();
    if (code != 0)
        System.exit(code);
}
Also used : Profiler(suite.sample.Profiler) IntSource(suite.primitive.IntPrimitives.IntSource) IntMutable(suite.primitive.IntMutable)

Example 4 with IntSource

use of suite.primitive.IntPrimitives.IntSource in project suite by stupidsing.

the class FunCreatorTest method testProfile.

@Test
public void testProfile() {
    Iterate<FunExpr> fun = i -> (ProfileFunExpr) f.profile(f.int_(1));
    IntSource instance = LambdaInstance.of(IntSource.class, fun).newFun();
    assertEquals(1, instance.source());
    Dump.out(instance);
}
Also used : Reference(suite.node.Reference) Suite(suite.Suite) Flt_Flt(suite.primitive.Flt_Flt) Dump(suite.inspect.Dump) PrintlnFunExpr(suite.jdk.gen.FunExprM.PrintlnFunExpr) Source(suite.util.FunUtil.Source) Assert.assertTrue(org.junit.Assert.assertTrue) TermOp(suite.node.io.TermOp) Test(org.junit.Test) Fun(suite.util.FunUtil.Fun) ProfileFunExpr(suite.jdk.gen.FunExprM.ProfileFunExpr) Tree(suite.node.Tree) Node(suite.node.Node) IntSource(suite.primitive.IntPrimitives.IntSource) Iterate(suite.util.FunUtil.Iterate) BiPredicate(java.util.function.BiPredicate) LambdaInstance(suite.jdk.lambda.LambdaInstance) Map(java.util.Map) Type(org.apache.bcel.generic.Type) FunExpr(suite.jdk.gen.FunExpression.FunExpr) Int(suite.node.Int) LambdaInterface(suite.jdk.lambda.LambdaInterface) Int_Int(suite.primitive.Int_Int) Assert.assertEquals(org.junit.Assert.assertEquals) ProfileFunExpr(suite.jdk.gen.FunExprM.ProfileFunExpr) IntSource(suite.primitive.IntPrimitives.IntSource) PrintlnFunExpr(suite.jdk.gen.FunExprM.PrintlnFunExpr) ProfileFunExpr(suite.jdk.gen.FunExprM.ProfileFunExpr) FunExpr(suite.jdk.gen.FunExpression.FunExpr) Test(org.junit.Test)

Example 5 with IntSource

use of suite.primitive.IntPrimitives.IntSource in project suite by stupidsing.

the class IntFunUtil method suck.

/**
 * Sucks data from a sink and produce into a source.
 */
public static IntSource suck(Sink<IntSink> fun) {
    NullableSyncQueue<Integer> queue = new NullableSyncQueue<>();
    IntSink 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 : 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_) IntObjSource(suite.primitive.IntPrimitives.IntObjSource) Fun(suite.util.FunUtil.Fun) IntSource(suite.primitive.IntPrimitives.IntSource) IntTest(suite.primitive.IntPrimitives.IntTest) Int_Obj(suite.primitive.IntPrimitives.Int_Obj) IntSink(suite.primitive.IntPrimitives.IntSink) IntObjPair(suite.primitive.adt.pair.IntObjPair) Sink(suite.util.FunUtil.Sink) Collections(java.util.Collections) Fail(suite.util.Fail) NullableSyncQueue(suite.util.NullableSyncQueue) IntSink(suite.primitive.IntPrimitives.IntSink)

Aggregations

IntSource (suite.primitive.IntPrimitives.IntSource)5 Fun (suite.util.FunUtil.Fun)2 Source (suite.util.FunUtil.Source)2 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 BiPredicate (java.util.function.BiPredicate)1 Type (org.apache.bcel.generic.Type)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Test (org.junit.Test)1 Suite (suite.Suite)1 Dump (suite.inspect.Dump)1 PrintlnFunExpr (suite.jdk.gen.FunExprM.PrintlnFunExpr)1 ProfileFunExpr (suite.jdk.gen.FunExprM.ProfileFunExpr)1 FunExpr (suite.jdk.gen.FunExpression.FunExpr)1 LambdaInstance (suite.jdk.lambda.LambdaInstance)1 LambdaInterface (suite.jdk.lambda.LambdaInterface)1 Int (suite.node.Int)1 Node (suite.node.Node)1