package com.example.playground.pattern.matching;

import com.sun.istack.internal.NotNull;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;

@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class PatternMatching<T, U> implements Function<T, Optional<U>> {
    private final Collection<Case> cases = new ArrayList<>();

    public static <T, U> PatternMatching<T, U> builder() {
        return new PatternMatching<>();
    }

    @Override
    public Optional<U> apply(final T t) {
        return cases.stream()
                .filter(c -> c.when.test(t))
                .findFirst()
                .map(c -> c.then);
    }

    public When when(@NotNull Predicate<? super T> when) {
        return new When(when);
    }

    public PatternMatching<T, U> otherwise(final U then) {
        return new When(t -> true).then(then);
    }

    @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
    public final class When {
        private final Predicate<? super T> when;

        public PatternMatching<T, U> then(@NotNull final U then) {
            cases.add(new Case(when, then));
            return PatternMatching.this;
        }
    }

    @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
    private final class Case {
        private final Predicate<? super T> when;
        private final U then;
    }
}

@@ -47,48 +47,8 @@
 g;%0A%0A
-import com.sun.istack.internal.NotNull;%0A
 impo
@@ -110,16 +110,61 @@
 uctor;%0A%0A
+import javax.validation.constraints.NotNull;%0A
 import j

Fix import