no.finn.unleash.repository.ToggleCollection 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
package no.finn.unleash.repository;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import no.finn.unleash.FeatureToggle;
public final class ToggleCollection {
private final Collection features;
private final int version = 1; // required for serialization
private final transient Map cache;
ToggleCollection(final Collection features) {
this.features = ensureNotNull(features);
this.cache = new ConcurrentHashMap<>();
for(FeatureToggle featureToggle : this.features) {
cache.put(featureToggle.getName(), featureToggle);
}
}
private Collection ensureNotNull(Collection features) {
if (features == null) { return Collections.emptyList(); }
return features;
}
public Collection getFeatures() {
return Collections.unmodifiableCollection(features);
}
public FeatureToggle getToggle(final String name) {
return cache.get(name);
}
}