Package net.jcores.jre.interfaces.functions

Examples of net.jcores.jre.interfaces.functions.F0


        // Make the drop panel accept files
        $(this.dropPanel).onDrop(new F1<CoreObject<Object>, Void>() {
            @Override
            public Void f(final CoreObject<Object> arg0) {
                $.sys.oneTime(new F0() {
                    @Override
                    public void f() {
                        process(arg0.as(CoreFile.class));
                    }
                }, 1);
View Full Code Here


            public File f(String x) {
                return new File(x.toLowerCase());
            }
        }).as(CoreObject.class);//.print();

        F0 f[] = new F0[] { new F0Impl(), new F0Impl(), new F0Impl() };
        $(f).each(F0.class).f();

        $(f).as(ExtensionCore.class).yoyo();
        //$(f).as(CoreSerializer.class).store("test.xml");
        //System.out.println($("test.xml").as(CoreSerializer.class).load().size());
View Full Code Here

    public void pack(Option... options) {
        // Check if we should create a console
        if (System.console() == null && this.console) {

            // In case we need a console, create it in the EDT
            $.ui.edtnow(new F0() {
                @Override
                public void f() {
                    initUI();
                    JCoresScriptRuntime.this.consoleWindow = new JCoresConsole(JCoresScriptRuntime.this.banner);
                }
View Full Code Here

            intobjs.add(i);
        }

        System.out.println();
        System.out.println("--- Array and Collections ---");
        System.out.println(benchmark(new F0() { // 9195
            public void f() {
                c1.toArray(new String[0]);
            }

        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 9460
            public void f() {
                c1.toArray();
            }

        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 62650
            public void f() {
                c2.toArray();
            }

        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 181898
            public void f() {
                c2.toArray(new String[0]);
            }

        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 84118
            public void f() {
                for (int i = 0; i < size; i++) {
                    strings[i] = c1.get(i).toLowerCase();
                }
            }

        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 80942
            public void f() {
                for (int i = 0; i < size; i++) {
                    strings[i] = strings[i].toLowerCase();
                }
            }

        }, 10) + "µs");
        r.clear();
        System.out.println(benchmark(new F0() { // 89496
            public void f() {
                for (String s : c1) {
                    r2.add(s.toLowerCase());
                }
            }
        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 87272
            public void f() {
                int i = 0;
                for (String s : c2) {
                    strings[i++] = s.toLowerCase();
                }
            }
        }, 10) + "µs");
        r.clear();
        System.out.println(benchmark(new F0() { // 413666
            public void f() {
                for (String s : c2) {
                    r.add(s.toLowerCase());
                }
            }
        }, 10) + "µs");
        r.clear();
        System.out.println(benchmark(new F0() { // 413666
            public void f() {
                for (String s : c2) {
                    r.add(s.toLowerCase());
                }
            }
        }, 10) + "µs");

        System.out.println();
        System.out.println("--- Object Creation ---");
        o1.clear();
        System.out.println(benchmark(new F0() { // 159663 (wo caching),
            // 356117 (w caching)
            // 331769
            // 14166 (optimized)
            public void f() {
                /*CoreClass<F0Impl> $2 = $(F0Impl.class);
                for (int i = 0; i < size; i++)
                    o1.add($2.spawn());*/
            }
        }, 10) + "µs");
        o1.clear();
        System.out.println(benchmark(new F0() { // 2277
            public void f() {
                for (int i = 0; i < size; i++)
                    o1.add(new F0Impl());
            }
        }, 10) + "µs");

        final AtomicInteger ress = new AtomicInteger();
        System.out.println();
        System.out.println("--- $() usage ---");
        System.out.println(benchmark(new F0() { // 15117
            public void f() {
                int cnt = 0;
                for (int i = 0; i < size; i++)
                    cnt += $(getOrNotObject()).compact().size();
                ress.addAndGet(cnt);
            }

        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 3034
            public void f() {
                int cnt = 0;
                for (int i = 0; i < size; i++) {
                    if (getOrNotObject() != null) cnt++;
                }
                ress.addAndGet(cnt);
            }

        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 227518
            public void f() {
                int cnt = 0;
                for (int i = 0; i < size; i++)
                    cnt += $(getOrNotList()).size();
                ress.addAndGet(cnt);
            }
        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 133315
            public void f() {
                int cnt = 0;
                for (int i = 0; i < size; i++) {
                    List<Object> orNotList = getOrNotList();
                    cnt += orNotList.size();
                }
                ress.addAndGet(cnt);
            }

        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 3857
            public void f() {
                Object o = new Object();
                int cnt = 0;
                for (int i = 0; i < size; i++)
                    cnt += $(o).size();
                ress.addAndGet(cnt);
            }
        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 30
            public void f() {
                Object o = new Object();
                int cnt = 0;
                for (int i = 0; i < size; i++) {
                    if (o != null) cnt += 1;
                }
                ress.addAndGet(cnt);
            }

        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 10409 // 839
            public void f() {
                int cnt = 0;
                Object o = new Object();
                for (int i = 0; i < size; i++) {
                    cnt += new Object().equals(o) ? 1 : 0;
                }
                ress.addAndGet(cnt);
            }

        }, 10) + "µs");
        System.out.println(benchmark(new F0() { // 12071 // 2782
            public void f() {
                int cnt = 0;
                Object o = new Object();
                for (int i = 0; i < size; i++) {
                    cnt += $(o).equals(o) ? 1 : 0;
                }
                ress.addAndGet(cnt);
            }
        }, 10) + "µs");

        System.out.println();
        System.out.println("--- Iteration over Created ---");
        System.out.println(benchmark(new F0() { // 278347
            public void f() {
                //$(F0Impl.class).spawned().each(F0.class).f();
            }
        }, 10) + "µs");
        System.out.println(benchmark(new F0() {
            public void f() { // 7450
                for (Object f0 : o1) {
                    ((F0Impl) f0).f();
                }
            }
        }, 10) + "µs");
        System.out.println(benchmark(new F0() {
            public void f() { // 118806
                $(o1).each(F0.class).f();
            }
        }, 10) + "µs");
        System.out.println(benchmark(new F0() {
            public void f() { // 26346
                $(o1).map(new F1() {
                    public Object f(Object x) {
                        ((F0) x).f();
                        return null;
                    }
                });
            }
        }, 10) + "µs");
        System.out.println(benchmark(new F0() {
            public void f() { // 11012
                $(o1);
            }
        }, 10) + "µs");

        /*
         * Removed, the ___map was the first version of map without the mapper, was ~10-20% faster but only
         * when F1 was very lightweight. For heavyweight cases of F1 no significant difference was noticable.
        long b11 = benchmark(new F0() {
            public void f() {
                $(strings).____map(new F1<String, String>() {
                    public String f(String x) {
                        return x.toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase();
                        //return x.toLowerCase();
                    }
                });
            }
        }, 10) + "µs";
         */
        long b1 = benchmark(new F0() {
            public void f() {
                $(strings).map(new F1<String, String>() {
                    public String f(String x) {
                        return x.toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase();
                        //return x.toLowerCase();
                    }
                });
            }
        }, 10);

        long b2 = benchmark(new F0() {
            public void f() {
                for (int i = 0; i < strings.length; i++) {
                    strings[i] = strings[i].toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase();
                    //strings[i] = strings[i].toLowerCase();
                }
            }
        }, 10);

        /*
        long b3 = benchmark(new F0() {
            public void f() {
                $(ints).map(new F1Int2Int() {
                    public int f(int x) {
                        return (int) Math.sqrt(Math.tan(x * x));
                    }
                });
            }
        }, 10);*/

        long b4 = benchmark(new F0() {
            public void f() {
                for (int i = 0; i < ints.length; i++) {
                    int x = ints[i];
                    res[i] = (int) Math.sqrt(Math.tan(x * x));
                }
            }
        }, 10);

        long b6 = benchmark(new F0() {
            public void f() {
                for (int i = 0; i < longs.length; i++) {
                    resl[i] = longs[i] * longs[i];
                }
            }
        }, 10);

        System.out.println();
        System.out.println("--- Parallelization Results ---");
        System.out.println(b1);
        System.out.println(b2);
        //System.out.println(b3);
        System.out.println(b4);
        System.out.println(b6);

        System.out.println();
        System.out.println("--- Fancy Stuff ---");
        System.out.println(benchmark(new F0() {
            public void f() {
                $(intobjs).fold(new F2ReduceObjects<Integer>() {
                    @Override
                    public Integer f(Integer stack, Integer next) {
                        return stack + next;
                    }
                }).get(0);
            }
        }, 10) + "µs");
        System.out.println(benchmark(new F0() {
            public void f() {
                $(intobjs).reduce(new F2ReduceObjects<Integer>() {
                    @Override
                    public Integer f(Integer stack, Integer next) {
                        return stack + next;
                    }
                }).get(0);
            }
        }, 10) + "µs");
        System.out.println(benchmark(new F0() {
            public void f() {

                /*$(intobjs).staple(0, new F2ReduceObjects<Integer>() {
                    public Integer f(Integer left, Integer right) {
                        return left + right;
                    }
                });*/

            }
        }, 10) + "µs");
        System.out.println(benchmark(new F0() {
            public void f() {
                $(intobjs).delta(new F2DeltaObjects<Integer, Integer>() {
                    public Integer f(Integer left, Integer right) {
                        return right - left;
                    }
View Full Code Here

     * @return A running {@link KillSwitch}.
     */
    public static final KillSwitch TIMED(long delay) {
        final KillSwitch killSwitch = new KillSwitch();
       
        $.sys.oneTime(new F0() {
            @Override
            public void f() {
                killSwitch.terminate();
            }
        }, delay);
View Full Code Here

    public <R> Async<R> async(final F0R<R> f, final Option... options) {
        final Queue<R> queue = Async.Queue();
        final Async<R> async = new Async<R>(this, queue);

        // Maybe use the executor right away?
        this.sys.oneTime(new F0() {
            @Override
            public void f() {
                try {
                    queue.add(Async.QEntry(f.f()));
                    queue.close();
View Full Code Here

     */
    public Async<T> onNext(final F1<T, Void> f, Option... options) {
        final Options options$ = Options.$(this.commonCore, options);
        final KillSwitch killswitch = options$.killswitch();

        $.sys.oneTime(new F0() {
            @Override
            public void f() {
                while (true) {
                    try {
                        // Get the elements, and wait.
View Full Code Here

        // Measure how long it takes to fork a thread and to wait for it again. We
        // test 10 times and take the average of the last 5 runs.
        long times[] = new long[RUNS];
        for (int i = 0; i < RUNS; i++) {
            times[i] = measure(new F0() {
                @Override
                public void f() {
                    final CyclicBarrier barrier = new CyclicBarrier(2);

                    // Execute the given task in the executor.
View Full Code Here

        final Queue<R> queue = Async.Queue();
        final Async<R> async = new Async<R>(this.commonCore, queue);
        final Options options$ = Options.$(this.commonCore, options);
        final KillSwitch killswitch = options$.killswitch();

        this.commonCore.sys.oneTime(new F0() {
            @Override
            public void f() {
                try {
                    // Now process all elements
                    for (T t : CoreObject.this) {
View Full Code Here

    setVisible(true);
  }

  public void addTerminationHook(final Thread thread) {
    $.sys.manyTimes(new F0() {
      boolean warned = false;

      @Override
      public void f() {
        if (!thread.isAlive() && !this.warned) {
View Full Code Here

TOP

Related Classes of net.jcores.jre.interfaces.functions.F0

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.