All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.getunleash.metric.ToggleCount Maven / Gradle / Ivy

There is a newer version: 9.2.4
Show newest version
package io.getunleash.metric;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;

class ToggleCount {
    private final AtomicLong yes;
    private final AtomicLong no;
    private final ConcurrentMap variants;

    public ToggleCount() {
        this.yes = new AtomicLong(0);
        this.no = new AtomicLong(0);
        this.variants = new ConcurrentHashMap<>();
    }

    public void register(boolean active) {
        if (active) {
            yes.incrementAndGet();
        } else {
            no.incrementAndGet();
        }
    }

    public void register(String variantName) {
        AtomicLong current = variants.computeIfAbsent(variantName, s -> new AtomicLong());
        current.incrementAndGet();
    }

    public long getYes() {
        return yes.get();
    }

    public long getNo() {
        return no.get();
    }

    public Map getVariants() {
        return variants;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy