protected void processArgs(CollectionTools.Closure<String, String> args) { String value; if ((value = args.execute("env")) != null) environment = Environment.parse(value); if ((value = args.execute("environment")) != null) environment = Environment.parse(value); if ((value = args.execute("profiles.active")) != null) Flow.of(value.split(",")).each(this::addProfile).execute(); }
@Test public void test_each_with_index() { final StringBuilder sb = new StringBuilder(); Flow.of(2, 4, 6).each(new ConsumerWithInt<Integer>() { @Override public void consume(int i, Integer integer) { if (sb.length() != 0) sb.append(", "); sb.append(i); } }).execute(); Assert.assertEquals("0, 1, 2", sb.toString()); }
@Test public void test_each() { final AtomicInteger counter = new AtomicInteger(); Flow.of(1, 2, 3).each(new Consumer<Integer>() { @Override public void consume(Integer integer) { counter.incrementAndGet(); } }).execute(); Assert.assertEquals(3, counter.get()); }
@Test public void test_async_non_blocking() { final AtomicInteger counter = new AtomicInteger(); Flow.of("a", "b", "c") .async(new Mapper<String, Flow<String>>() { @Override public Flow<String> map(String s) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } counter.incrementAndGet(); return Flow.of(s); } }).execute(); Assert.assertEquals(0, counter.get()); try { Thread.sleep(350); } catch (InterruptedException e) { e.printStackTrace(); } Assert.assertEquals(3, counter.get()); }
@Test public void test_each_after_first() { final AtomicInteger before = new AtomicInteger(); final AtomicInteger after = new AtomicInteger(); Flow.of(1, 2, 3) .each(new Consumer<Integer>() { @Override public void consume(Integer i) { before.incrementAndGet(); } }) .first() .each(new Consumer<Integer>() { @Override public void consume(Integer i) { after.incrementAndGet(); } }) .execute(); Assert.assertEquals(1, before.get()); Assert.assertEquals(1, after.get()); }