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

no.finn.unleash.metric.ToggleCount Maven / Gradle / Ivy

There is a newer version: 4.4.1
Show newest version
package no.finn.unleash.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