io.getunleash.metric.ToggleCount Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unleash-client-java Show documentation
Show all versions of unleash-client-java Show documentation
A client library for Unleash
The 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;
}
}