1 /*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.common
.core
.collect
;
12 import java
.util
.function
.Function
;
13 import java
.util
.stream
.Stream
;
16 * Generic utility class to "flatten" a data structure using the {@link Stream}
19 * @author Alexandre Montplaisir
22 * The type of container, or "node" in the tree
25 public class StreamFlattener
<T
> {
27 private final Function
<T
, Stream
<T
>> fGetChildrenFunction
;
32 * @param getChildrenFunction
33 * The function to use to get each element's children. Should
34 * return a {@link Stream} of those children.
36 public StreamFlattener(Function
<T
, Stream
<T
>> getChildrenFunction
) {
37 fGetChildrenFunction
= getChildrenFunction
;
41 * Do an in-order flattening of the data structure, starting at the given
45 * The tree node or similar from which to start
46 * @return A unified Stream of all the children that were found,
49 public Stream
<T
> flatten(T element
) {
52 fGetChildrenFunction
.apply(element
).flatMap(this::flatten
));
This page took 0.040031 seconds and 5 git commands to generate.