aboutsummaryrefslogtreecommitdiffstats
path: root/flags/src/main/java/com/yahoo/vespa/flags/Flag.java
blob: 0ca9dbb4cf78ca5434296c7d481d1e0f88e5caa0 (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
33
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.flags;

import java.util.Optional;

/**
 * Interface for flag.
 *
 * @param <T> The type of the flag value (boxed for primitives)
 * @param <F> The concrete subclass type of the flag
 * @author hakonhall
 */
public interface Flag<T, F> {
    /** The flag ID. */
    FlagId id();

    /** A generic type-safe method for getting {@code this}. */
    F self();

    /** Returns the flag serializer. */
    FlagSerializer<T> serializer();

    /** Returns an immutable clone of the current object, except with the dimension set accordingly. */
    F with(FetchVector.Dimension dimension, String dimensionValue);

    /** Same as {@link #with(FetchVector.Dimension, String)} if value is present, and otherwise returns {@code this}. */
    default F with(FetchVector.Dimension dimension, Optional<String> dimensionValue) {
        return dimensionValue.map(value -> with(dimension, value)).orElse(self());
    }

    /** Returns the value, boxed if the flag wraps a primitive type. */
    T boxedValue();
}