com.yahoo.vespa.flags.FetchVector Maven / Gradle / Ivy
// 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.Collection;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
/**
* Denotes which RawFlag should be retrieved from {@link FlagSource} for a given {@link FlagId},
* as the raw flag may depend on the hostname, application, etc.
*
* @author hakonhall
*/
public class FetchVector {
private final Map map;
public FetchVector() {
this.map = Map.of();
}
public static FetchVector fromMap(Map map) {
return new FetchVector(map);
}
private FetchVector(Map map) {
this.map = Map.copyOf(map);
}
public Optional getValue(Dimension dimension) {
return Optional.ofNullable(map.get(dimension));
}
public Map toMap() { return map; }
public boolean isEmpty() { return map.isEmpty(); }
public boolean hasDimension(Dimension dimension) { return map.containsKey(dimension);}
public Set dimensions() { return map.keySet(); }
/**
* Returns a new FetchVector, identical to {@code this} except for its value in {@code dimension}.
* Dimension is removed if the value is null.
*/
public FetchVector with(Dimension dimension, String value) {
if (value == null) return makeFetchVector(merged -> merged.remove(dimension));
return makeFetchVector(merged -> merged.put(dimension, value));
}
/** Returns a new FetchVector, identical to {@code this} except for its values in the override's dimensions. */
public FetchVector with(FetchVector override) {
return makeFetchVector(vector -> vector.putAll(override.map));
}
private FetchVector makeFetchVector(Consumer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy