package com.wizzardo.tools.collections.flow.flows;

import com.wizzardo.tools.collections.flow.FlowGroup;
import com.wizzardo.tools.collections.flow.FlowProcessor;
import com.wizzardo.tools.collections.flow.Mapper;

import java.util.Map;

/**
 * Created by wizzardo on 16.04.16.
 */
public class FlowToMap<K, V, B extends FlowGroup<K, ?>> extends FlowProcessor<B,Map<K,V>> {
    private final Map<K, V> groups;
    private final Mapper<? super B, V> mapper;

    public FlowToMap(Map<K, V> groups, Mapper<? super B, V> mapper) {
        this.groups = groups;
        this.mapper = mapper;
    }

    @Override
    public void process(final B b) {
        mapper.map(b);
        getLast(b).then(new FlowOnEnd<V>(new FlowProcessor<V, V>() {
            @Override
            public void process(V v) {
                groups.put(b.getKey(), v);
            }
        }));
    }

    @Override
    public Map<K, V> get() {
        return groups;
    }
}

@@ -355,61 +355,30 @@
 cess
-or
+OnEnd
 %3CB,
+ 
 Map%3CK,
+ 
 V%3E%3E %7B%0A
-    private final Map%3CK, V%3E groups;%0A
     
@@ -504,22 +504,22 @@
    this.
-groups
+result
  = group
@@ -778,22 +778,22 @@
         
-groups
+result
 .put(b.g
@@ -841,80 +841,7 @@
    %7D
-%0A%0A    @Override%0A    public Map%3CK, V%3E get() %7B%0A        return groups;%0A    %7D
 %0A%7D%0A

update 'toMap'