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

dev.openfeature.sdk.internal.ObjectUtils Maven / Gradle / Ivy

Go to download

This is the Java implementation of OpenFeature, a vendor-agnostic abstraction library for evaluating feature flags.

The newest version!
package dev.openfeature.sdk.internal;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import lombok.experimental.UtilityClass;

@SuppressWarnings("checkstyle:MissingJavadocType")
@UtilityClass
public class ObjectUtils {

    /**
     * If the source param is null, return the default value.
     * @param source maybe null object
     * @param defaultValue thing to use if source is null
     * @param  list type
     * @return resulting object
     */
    public static  List defaultIfNull(List source, Supplier> defaultValue) {
        if (source == null) {
            return defaultValue.get();
        }
        return source;
    }

    /**
     * If the source param is null, return the default value.
     * @param source maybe null object
     * @param defaultValue thing to use if source is null
     * @param  map key type
     * @param  map value type
     * @return resulting map
     */
    public static  Map defaultIfNull(Map source, Supplier> defaultValue) {
        if (source == null) {
            return defaultValue.get();
        }
        return source;
    }

    /**
     * If the source param is null, return the default value.
     * @param source maybe null object
     * @param defaultValue thing to use if source is null
     * @param  type
     * @return resulting object
     */
    public static  T defaultIfNull(T source, Supplier defaultValue) {
        if (source == null) {
            return defaultValue.get();
        }
        return source;
    }

    /**
     * Concatenate a bunch of lists.
     * @param sources bunch of lists.
     * @param  list type
     * @return resulting object
     */
    @SafeVarargs
    public static  List merge(List... sources) {
        return Arrays
            .stream(sources)
            .flatMap(Collection::stream)
            .collect(Collectors.toList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy