aboutsummaryrefslogtreecommitdiffstats
path: root/flags/src/main/java/com/yahoo/vespa/flags/json/FetchVectorHelper.java
blob: c0bb3128924adc1eb8a97cdd00154742cc2c2342 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.flags.json;

import com.yahoo.vespa.flags.FetchVector;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author hakonhall
 */
public class FetchVectorHelper {

    public static Map<String, String> toWire(FetchVector vector) {
        Map<FetchVector.Dimension, String> map = vector.toMap();
        if (map.isEmpty()) return null;
        return map.entrySet().stream().collect(Collectors.toMap(
                entry -> DimensionHelper.toWire(entry.getKey()),
                Map.Entry::getValue));
    }

    public static FetchVector fromWire(Map<String, String> wireMap) {
        if (wireMap == null) return new FetchVector();
        return FetchVector.fromMap(wireMap.entrySet().stream().collect(Collectors.toMap(
                entry -> DimensionHelper.fromWire(entry.getKey()),
                Map.Entry::getValue)));
    }

}