[ 
https://issues.apache.org/jira/browse/QUARKS-18?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15195511#comment-15195511
 ] 

ASF GitHub Bot commented on QUARKS-18:
--------------------------------------

Github user dlaboss commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/11#discussion_r56185779
  
    --- Diff: 
spi/topology/src/main/java/quarks/topology/spi/graph/ConnectorStream.java ---
    @@ -96,6 +89,35 @@ protected Graph graph() {
         }
     
         @Override
    +    public <E extends Enum<E>> EnumMap<E,TStream<T>> split(Class<E> 
enumClass, Function<T, E> splitter) {
    +
    +        E[] es = enumClass.getEnumConstants();
    +
    +/*
    +        List<TStream<T>> outputs = split(es.length, e -> 
IntStream.range(0, es.length).filter(i-> es[i].equals(splitter.apply(e)))
    +            .mapToObj(i -> es[i].ordinal()).findAny().orElse(-1));
    +*/
    +
    +        List<TStream<T>> outputs = split(es.length, new ToIntFunction<T>() 
{
    +            @Override
    +            public int applyAsInt(T input) {
    +                for(int i = 0; i < es.length; i++){
    --- End diff --
    
    I was also going to comment on simplifying the fn.  And (then eliminating 
the need for the intermediate "es" variable) I think the returnMap construction 
could be simplified to:
    ```
    for (E e : enumClass.getEnumConstants()) {
        returnMap.put(e, outputs.get(e.ordinal());
    }
    ```


> Split function based upon an enumeration.
> -----------------------------------------
>
>                 Key: QUARKS-18
>                 URL: https://issues.apache.org/jira/browse/QUARKS-18
>             Project: Quarks
>          Issue Type: Improvement
>          Components: API
>            Reporter: Daniel John Debrunner
>            Priority: Minor
>              Labels: newbie
>         Attachments: SplitWithEnum_Screenshot.png
>
>
> An enum based split would be useful.
> Something like:
> <E> List<TStream<T>> split(Class<E> enumClass, Function<T,E> splitter)
> So the stream is split by the enum value with the returned streams in ordinal 
> order.
> This may have the benefit of being self-maintaining, so that if an enum value 
> is added, the returned number of streams changes automatically, but only if 
> given an enum class one can figure out the number of enums.
> Based upon looking at the sample code in QUARKS-16



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to