Search in sources :

Example 1 with IntMutable

use of suite.primitive.IntMutable 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 2 with IntMutable

use of suite.primitive.IntMutable in project suite by stupidsing.

the class DevMain method text.

private Text text(IRopeList<Character> text) {
    IntsBuilder starts = new IntsBuilder();
    IntsBuilder ends = new IntsBuilder();
    IntMutable p0 = IntMutable.of(-1);
    int size = text.size();
    IntSink lf = px -> {
        starts.append(p0.get() + 1);
        ends.append(px);
        p0.update(px);
    };
    for (int p = 0; p < size; p++) {
        char ch = text.get(p);
        if (ch == '\n' || wrapSize < p - p0.get())
            lf.sink(p);
    }
    if (1 < size - p0.get())
        lf.sink(size);
    return new Text(text, starts.toInts().toArray(), ends.toInts().toArray());
}
Also used : LibcJna(suite.ansi.LibcJna) Termios(suite.ansi.Termios) Friends.min(suite.util.Friends.min) Native(com.sun.jna.Native) IntIntPair(suite.primitive.adt.pair.IntIntPair) Predicate(java.util.function.Predicate) IRope(suite.immutable.IRope) Friends.max(suite.util.Friends.max) IntSink(suite.primitive.IntPrimitives.IntSink) Keyboard(suite.ansi.Keyboard) IRopeList(suite.immutable.IRope.IRopeList) FixieFun6(suite.adt.pair.Fixie_.FixieFun6) VK(suite.ansi.Keyboard.VK) FixieFun3(suite.adt.pair.Fixie_.FixieFun3) Sink(suite.util.FunUtil.Sink) FileUtil(suite.os.FileUtil) Chars_(suite.primitive.Chars_) IntsBuilder(suite.primitive.Ints.IntsBuilder) Ints_(suite.primitive.Ints_) IntMutable(suite.primitive.IntMutable) Fail(suite.util.Fail) IntSink(suite.primitive.IntPrimitives.IntSink) IntsBuilder(suite.primitive.Ints.IntsBuilder) IntMutable(suite.primitive.IntMutable)

Aggregations

IntMutable (suite.primitive.IntMutable)2 Native (com.sun.jna.Native)1 Predicate (java.util.function.Predicate)1 FixieFun3 (suite.adt.pair.Fixie_.FixieFun3)1 FixieFun6 (suite.adt.pair.Fixie_.FixieFun6)1 Keyboard (suite.ansi.Keyboard)1 VK (suite.ansi.Keyboard.VK)1 LibcJna (suite.ansi.LibcJna)1 Termios (suite.ansi.Termios)1 IRope (suite.immutable.IRope)1 IRopeList (suite.immutable.IRope.IRopeList)1 FileUtil (suite.os.FileUtil)1 Chars_ (suite.primitive.Chars_)1 IntSink (suite.primitive.IntPrimitives.IntSink)1 IntSource (suite.primitive.IntPrimitives.IntSource)1 IntsBuilder (suite.primitive.Ints.IntsBuilder)1 Ints_ (suite.primitive.Ints_)1 IntIntPair (suite.primitive.adt.pair.IntIntPair)1 Profiler (suite.sample.Profiler)1 Fail (suite.util.Fail)1