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

io.sphere.sdk.utils.functional.PatternMatcher Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
package io.sphere.sdk.utils.functional;

import io.sphere.sdk.models.Base;

import javax.annotation.Nullable;
import java.util.function.Function;

public class PatternMatcher extends Base {
    private final Object thing;
    @Nullable
    private final T result;

    PatternMatcher(final Object thing, @Nullable final T result) {
        this.thing = thing;
        this.result = result;
    }

    @SuppressWarnings("unchecked")
    public  PatternMatcher when(final Class type, final Function f) {
        final boolean noActionRequired = result != null || !type.isAssignableFrom(thing.getClass());
        return noActionRequired ? this : new PatternMatcher<>(this.thing, f.apply((C) this.thing));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy