congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
FlowGrouping
Code IndexAdd Tabnine to your IDE (free)

How to use
FlowGrouping
in
com.wizzardo.tools.collections.flow

Best Java code snippets using com.wizzardo.tools.collections.flow.FlowGrouping (Showing top 20 results out of 315)

origin: com.wizzardo.tools/tools-collections

public FlowToMap<K, List<T>, B> toMap() {
  return toMap(Flow.<K, T>flowGroupListMapper());
}
origin: com.wizzardo.tools/tools-collections

  @Override
  protected void onEnd() {
    for (FlowGroup<K, B> group : groups.values()) {
      onEnd(group);
    }
    super.onEnd();
  }
}
origin: com.wizzardo.tools/tools-collections

public FlowGrouping<K, T, B, B> each(final ConsumerWithInt<? super B> consumer) {
  return then(new FlowGrouping<K, T, B, B>(groups) {
    int index = 0;
    @Override
    public void process(B b) {
      consumer.consume(index++, b);
      FlowProcessor<B, ?> child = this.child;
      if (child != null)
        child.process(b);
    }
  });
}
origin: wizzardo/tools

@Test
public void test_limit_3() {
  Assert.assertEquals("{1=[1], 2=[2], 3=[3]}", Flow.of(1, 2, 3, 4, 5)
      .groupBy(new Mapper<Integer, Integer>() {
        @Override
        public Integer map(Integer integer) {
          return integer;
        }
      })
      .limit(3)
      .toMap()
      .get()
      .toString()
  );
}
origin: wizzardo/tools

@Test
public void test_toMap_3() {
  Map<Boolean, List<Integer>> map = Flow.of(1, 2, 3)
      .groupBy(new Mapper<Integer, Boolean>() {
        @Override
        public Boolean map(Integer integer) {
          return integer % 2 == 0;
        }
      })
      .filter(new Filter<FlowGroup<Boolean, Integer>>() {
        @Override
        public boolean allow(FlowGroup<Boolean, Integer> group) {
          return group.getKey();
        }
      })
      .toMap()
      .get();
  Assert.assertEquals(1, map.size());
  Assert.assertEquals(1, map.get(true).size());
  Assert.assertEquals(Integer.valueOf(2), map.get(true).get(0));
}
origin: wizzardo/tools

@Test
public void test_each_2() {
  final AtomicInteger counter = new AtomicInteger();
  Flow.of(1, 2, 3)
      .groupBy(new Mapper<Integer, Boolean>() {
        @Override
        public Boolean map(Integer integer) {
          return integer % 2 == 0;
        }
      })
      .each(new Consumer<FlowGroup<Boolean, Integer>>() {
        @Override
        public void consume(FlowGroup<Boolean, Integer> group) {
          counter.incrementAndGet();
        }
      }).execute();
  Assert.assertEquals(2, counter.get());
}
origin: wizzardo/tools

@Test
public void test_each_3() {
  final AtomicInteger counter = new AtomicInteger();
  Flow.of(1, 2, 3)
      .groupBy(new Mapper<Integer, Boolean>() {
        @Override
        public Boolean map(Integer integer) {
          return integer % 2 == 0;
        }
      })
      .each(new Consumer<FlowGroup<Boolean, Integer>>() {
        @Override
        public void consume(FlowGroup<Boolean, Integer> group) {
          counter.incrementAndGet();
        }
      })
      .first()
      .get();
  Assert.assertEquals(1, counter.get());
}
origin: wizzardo/tools

@Test
public void test_merge_2() {
  List<Integer> result = Flow.of(1, 2, 3, 4, 5, 6)
      .groupBy(new Mapper<Integer, Boolean>() {
        @Override
        public Boolean map(Integer integer) {
          return integer % 2 == 0;
        }
      })
      .filter(new Filter<FlowGroup<Boolean, Integer>>() {
        @Override
        public boolean allow(FlowGroup<Boolean, Integer> group) {
          return group.getKey();
        }
      })
      .merge()
      .toList()
      .get();
  Assert.assertEquals(3, result.size());
  Assert.assertEquals(Integer.valueOf(2), result.get(0));
  Assert.assertEquals(Integer.valueOf(4), result.get(1));
  Assert.assertEquals(Integer.valueOf(6), result.get(2));
}
origin: wizzardo/tools

.filter(new Filter<FlowGroup<Boolean, Integer>>() {
  @Override
  public boolean allow(FlowGroup<Boolean, Integer> group) {
.flatMap(new Mapper<FlowGroup<Boolean, Integer>, FlowProcessOnEnd<?, ArrayList<Integer>>>() {
  int counter = 0;
origin: wizzardo/tools

@Test
public void test_limit_2() {
  Assert.assertEquals("1,2,3", Flow.of(1, 2, 3, 4, 5)
      .groupBy(new Mapper<Integer, Integer>() {
        @Override
        public Integer map(Integer integer) {
          return integer;
        }
      })
      .limit(3)
      .map(new Mapper<FlowGroup<Integer, Integer>, Integer>() {
        @Override
        public Integer map(FlowGroup<Integer, Integer> group) {
          return group.key;
        }
      })
      .join(",")
      .get());
}
origin: wizzardo/tools

@Test
public void test_flatMap_2() {
  ArrayList<Integer> integers = Flow.of(1, 2, 3)
      .groupBy(new Mapper<Integer, Boolean>() {
        @Override
        public Boolean map(Integer it) {
          return it % 2 == 0;
        }
      })
      .flatMap(new Mapper<FlowGroup<Boolean, Integer>, Flow<Integer>>() {
        @Override
        public Flow<Integer> map(final FlowGroup<Boolean, Integer> group) {
          return group;
        }
      })
      .toList().get();
  Assert.assertEquals(3, integers.size());
  Assert.assertEquals(Integer.valueOf(1), integers.get(0));
  Assert.assertEquals(Integer.valueOf(2), integers.get(1));
  Assert.assertEquals(Integer.valueOf(3), integers.get(2));
}
origin: wizzardo/tools

@Test
public void test_each_with_index_2() {
  final StringBuilder sb = new StringBuilder();
  Flow.of(2, 4, 6)
      .groupBy(new Mapper<Integer, Integer>() {
        @Override
        public Integer map(Integer integer) {
          return integer;
        }
      })
      .each(new ConsumerWithInt<FlowGroup<Integer, Integer>>() {
        @Override
        public void consume(int i, FlowGroup<Integer, Integer> integerIntegerFlowGroup) {
          if (sb.length() != 0)
            sb.append(", ");
          sb.append(i);
        }
      })
      .execute();
  Assert.assertEquals("0, 1, 2", sb.toString());
}
origin: wizzardo/tools

@Test
public void test_each_with_index_4() {
  final StringBuilder sb = new StringBuilder();
  Flow.of(2, 4, 6)
      .groupBy(new Mapper<Integer, Integer>() {
        @Override
        public Integer map(Integer integer) {
          return integer;
        }
      })
      .each(new ConsumerWithInt<FlowGroup<Integer, Integer>>() {
        @Override
        public void consume(int i, FlowGroup<Integer, Integer> integerIntegerFlowGroup) {
          if (sb.length() != 0)
            sb.append(", ");
          sb.append(i);
        }
      })
      .first()
      .get();
  Assert.assertEquals("0", sb.toString());
}
origin: wizzardo/tools

@Test
public void test_grouping_1() {
  List<ArrayList<Integer>> result = Flow.of(1, 2, 3)
      .groupBy(new Mapper<Integer, Boolean>() {
        @Override
        public Boolean map(Integer it) {
          return it % 2 == 0;
        }
      })
      .flatMap(new Mapper<FlowGroup<Boolean, Integer>, FlowProcessOnEnd<?, ArrayList<Integer>>>() {
        @Override
        public FlowProcessOnEnd<?, ArrayList<Integer>> map(FlowGroup<Boolean, Integer> group) {
          return group.toList();
        }
      })
      .toSortedList(new Comparator<List<Integer>>() {
        @Override
        public int compare(List<Integer> o1, List<Integer> o2) {
          return o1.size() < o2.size() ? -1 : (o1.size() == o2.size() ? 0 : 1);
        }
      }).get();
  Assert.assertEquals(2, result.size());
  Assert.assertEquals(1, result.get(0).size());
  Assert.assertEquals(Integer.valueOf(2), result.get(0).get(0));
  Assert.assertEquals(2, result.get(1).size());
  Assert.assertEquals(Integer.valueOf(1), result.get(1).get(0));
  Assert.assertEquals(Integer.valueOf(3), result.get(1).get(1));
}
origin: wizzardo/tools

public FlowGrouping<K, T, B, B> each(final ConsumerWithInt<? super B> consumer) {
  return then(new FlowGrouping<K, T, B, B>(groups) {
    int index = 0;
    @Override
    public void process(B b) {
      consumer.consume(index++, b);
      FlowProcessor<B, ?> child = this.child;
      if (child != null)
        child.process(b);
    }
  });
}
origin: com.wizzardo.tools/tools-collections

public <K, V> FlowToMap<K, V, FlowGroup<K, B>> toMap(Supplier<Map<K, FlowGroup<K, B>>> groupMapSupplier, Mapper<B, K> toKey, Mapper<FlowGroup<K, B>, V> toValue) {
  return groupBy(toKey, groupMapSupplier).toMap(toValue);
}
origin: wizzardo/tools

  @Override
  protected void onEnd() {
    for (FlowGroup<K, B> group : groups.values()) {
      onEnd(group);
    }
    super.onEnd();
  }
}
origin: wizzardo/tools

@Test
public void test_grouping_3() {
  List<Integer> result = Flow.of(1, 2, 3)
      .groupBy(new Mapper<Integer, Boolean>() {
        @Override
        public Boolean map(Integer it) {
          return it % 2 == 0;
        }
      })
      .flatMap(new Mapper<FlowGroup<Boolean, Integer>, FlowProcessOnEnd<?, Integer>>() {
        @Override
        public FlowProcessOnEnd<?, Integer> map(FlowGroup<Boolean, Integer> group) {
          return group.first();
        }
      })
      .toSortedList()
      .get();
  Assert.assertEquals(2, result.size());
  Assert.assertEquals(Integer.valueOf(1), result.get(0));
  Assert.assertEquals(Integer.valueOf(2), result.get(1));
}
origin: com.wizzardo.tools/tools-collections

@Override
public FlowGrouping<K, T, B, B> each(final Consumer<? super B> consumer) {
  return this.then(new FlowGrouping<K, T, B, B>(groups) {
    @Override
    public void process(B b) {
      consumer.consume(b);
      FlowProcessor<B, ?> child = this.child;
      if (child != null)
        child.process(b);
    }
  });
}
origin: wizzardo/tools

public FlowToMap<K, List<T>, B> toMap() {
  return toMap(Flow.<K, T>flowGroupListMapper());
}
com.wizzardo.tools.collections.flowFlowGrouping

Javadoc

Created by wizzardo on 08.11.15.

Most used methods

  • toMap
  • onEnd
  • then
  • each
  • execute
  • filter
  • first
  • flatMap
  • limit
  • map
  • merge
  • skip
  • merge,
  • skip

Popular in Java

  • Finding current android device location
  • getSupportFragmentManager (FragmentActivity)
  • notifyDataSetChanged (ArrayAdapter)
  • findViewById (Activity)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • JFileChooser (javax.swing)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now