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

no.finn.unleash.repository.ToggleCollection Maven / Gradle / Ivy

There is a newer version: 4.4.1
Show newest version
package no.finn.unleash.repository;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import no.finn.unleash.FeatureToggle;

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

    ToggleCollection(final Collection features) {
        this.features = ensureNotNull(features);
        this.cache = new HashMap<>();
        for(FeatureToggle featureToggle : this.features) {
            cache.put(featureToggle.getName(), featureToggle);
        }
    }

    private Collection ensureNotNull(Collection features) {
        if (features == null) { return Collections.emptyList(); }
        return features;
    }

    Collection getFeatures() {
        return features;
    }

    FeatureToggle getToggle(final String name) {
        return cache.get(name);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy