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

de.otto.edison.togglz.controller.TogglzRepresentation Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
package de.otto.edison.togglz.controller;

import de.otto.edison.togglz.FeatureClassProvider;
import net.jcip.annotations.Immutable;
import org.togglz.core.Feature;

import java.util.Map;

import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toMap;
import static org.togglz.core.context.FeatureContext.getFeatureManager;

@Immutable
public class TogglzRepresentation {

    private final Map togglzState;

    private TogglzRepresentation(final Class featureClass) {
        this.togglzState = buildTogglzState(featureClass);
    }

    public static TogglzRepresentation togglzRepresentation(final FeatureClassProvider featureClassProvider) {
        return new TogglzRepresentation((Class) featureClassProvider.getFeatureClass());
    }

    private Map buildTogglzState(final Class featureClass) {
        return asList(featureClass.getEnumConstants()).stream()
                .collect(toMap(this::toggleName, this::toggleState));
    }

    private boolean toggleState(Feature feature) {
        return getFeatureManager().getFeatureState(feature).isEnabled();
    }

    private String toggleName(Feature features) {
        return features.name();
    }

    public Map getTogglzState() {
        return togglzState;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy