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

io.molr.commons.domain.Placeholders Maven / Gradle / Ivy

package io.molr.commons.domain;

import com.google.common.collect.ImmutableSet;

import java.util.Optional;
import java.util.Set;

public final class Placeholders {

    private static final String RETURN_VALUE_KEY = "returnValue";
    private static final String THROWABLE_KEY = "throwable";

    public static final Placeholder RETURNED_STRING = Placeholder.aString(RETURN_VALUE_KEY);
    public static final Placeholder RETURNED_INTEGER = Placeholder.anInteger(RETURN_VALUE_KEY);
    public static final Placeholder RETURNED_DOUBLE = Placeholder.aDouble(RETURN_VALUE_KEY);
    public static final Placeholder RETURNED_BOOLEAN = Placeholder.aBoolean(RETURN_VALUE_KEY);

    private static final Set> ALL_RETURN_VALUES = ImmutableSet.of(RETURNED_STRING, RETURNED_INTEGER,
            RETURNED_DOUBLE, RETURNED_BOOLEAN);

    public static final Placeholder THROWN = Placeholder.aString(THROWABLE_KEY);

    private Placeholders() {
        /* only constants and methods */
    }

    public static  Optional> returned(Class returnType) {
        return ALL_RETURN_VALUES.stream().filter(p -> p.type().isAssignableFrom(returnType)).map(p -> (Placeholder) p).findAny();
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy