blob: 855e388d69ad845f7ae0aa853d9e6053544e6ba2 (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.flags;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
/**
* A {@link FlagSource#fetch(FlagId, FetchVector) fetch} on this flag source will return the {@link RawFlag}
* from the first (highest priority) flag source that returns a raw flag for the fetch vector.
*
* @author hakonhall
*/
public class OrderedFlagSource implements FlagSource {
private final List<FlagSource> sources;
/**
* @param sources Flag sources in descending priority order.
*/
public OrderedFlagSource(FlagSource... sources) {
this.sources = Arrays.asList(sources);
}
@Override
public Optional<RawFlag> fetch(FlagId id, FetchVector vector) {
return sources.stream()
.map(source -> source.fetch(id, vector))
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst();
}
}
|