aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/fr/umlv/java/wallj/context/Updateables.java
blob: 8f66c93405ea02302f8f7756451f4392f6ec3174 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package fr.umlv.java.wallj.context;

import fr.umlv.java.wallj.event.Event;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * Updateables utilities.
 *
 * @author Pacien TRAN-GIRARD
 */
public final class Updateables {
  private Updateables() {
    // static class
  }

  /**
   * @param <T>         the updateable type
   * @param context     an update context
   * @param updateables list of updateables
   * @return a stream of generated events
   */
  public static <T extends Updateable> Stream<Event> updateAll(Context context, List<T> updateables) {
    return updateables.stream()
           .flatMap(u -> u.update(context));
  }

  /**
   * @param <T>         the updateable type
   * @param context     an update context
   * @param updateables list of updateables
   * @return a stream of generated events
   */
  @SafeVarargs
  public static <T extends Updateable> Stream<Event> updateAll(Context context, T... updateables) {
    return updateAll(context, Arrays.asList(updateables));
  }
}