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

io.getunleash.util.ConstraintMerger Maven / Gradle / Ivy

There is a newer version: 9.2.4
Show newest version
package io.getunleash.util;

import static io.getunleash.Segment.DENY_SEGMENT;

import io.getunleash.ActivationStrategy;
import io.getunleash.Constraint;
import io.getunleash.Segment;
import io.getunleash.repository.IFeatureRepository;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ConstraintMerger {
    public static List mergeConstraints(
            IFeatureRepository repository, ActivationStrategy strategy) {
        return Stream.of(
                        Optional.ofNullable(strategy.getConstraints())
                                .orElseGet(Collections::emptyList),
                        Optional.ofNullable(strategy.getSegments())
                                .orElseGet(Collections::emptyList)
                                .stream()
                                .map(repository::getSegment)
                                .map(s -> s == null ? DENY_SEGMENT : s)
                                .map(Segment::getConstraints)
                                .flatMap(Collection::stream)
                                .collect(Collectors.toList()))
                .flatMap(Collection::stream)
                .collect(Collectors.toList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy