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

io.split.client.api.SplitView Maven / Gradle / Ivy

The newest version!
package io.split.client.api;

import io.split.client.dtos.Partition;
import io.split.engine.experiments.ParsedCondition;
import io.split.engine.experiments.ParsedSplit;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;


/**
 * A view of a Split meant for consumption through SplitManager interface.
 *
 * @author adil
 */
public class SplitView {
    public String name;
    public String trafficType;
    public boolean killed;
    public List treatments;
    public long changeNumber;
    public Map configs;
    public List sets;
    public String defaultTreatment;

    public static SplitView fromParsedSplit(ParsedSplit parsedSplit) {
        SplitView splitView = new SplitView();
        splitView.name = parsedSplit.feature();
        splitView.trafficType = parsedSplit.trafficTypeName();
        splitView.killed = parsedSplit.killed();
        splitView.changeNumber = parsedSplit.changeNumber();
        splitView.sets = parsedSplit.flagSets() != null ? new ArrayList<>(parsedSplit.flagSets()): new ArrayList<>();
        splitView.defaultTreatment = parsedSplit.defaultTreatment();

        Set treatments = new HashSet();
        for (ParsedCondition condition : parsedSplit.parsedConditions()) {
            for (Partition partition : condition.partitions()) {
                treatments.add(partition.treatment);
            }
        }
        treatments.add(parsedSplit.defaultTreatment());

        splitView.treatments = new ArrayList(treatments);
        splitView.configs = parsedSplit.configurations() == null? Collections.emptyMap() : parsedSplit.configurations() ;

        return splitView;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy