io.sphere.sdk.utils.functional.PatternMatcher Maven / Gradle / Ivy
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 super C> 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