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

io.getunleash.repository.ToggleCollection Maven / Gradle / Ivy

The newest version!
package io.getunleash.repository;

import io.getunleash.FeatureToggle;
import io.getunleash.lang.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public final class ToggleCollection {
    private final Collection features;
    private final int version = 1; // required for serialization
    private final transient Map cache;

    public 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(@Nullable 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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy