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;
}
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);
}
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);
}
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);
}
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);
}
};
}
Aggregations