package org.monospark.spongematchers.matcher.base;

import java.util.Optional;

import org.monospark.spongematchers.matcher.SpongeMatcher;

public final class OptionalMatcher {

    private OptionalMatcher() {}
    
    public static <T> SpongeMatcher<Optional<T>> falseOnEmpty(SpongeMatcher<T> matcher) {
        return create(matcher, false); 
    }
    
    public static <T> SpongeMatcher<Optional<T>> trueOnEmpty(SpongeMatcher<T> matcher) {
        return create(matcher, true); 
    }
    
    public static <T> SpongeMatcher<Optional<T>> create(SpongeMatcher<T> matcher, boolean matchOnEmpty) {
        return new SpongeMatcher<Optional<T>>() {
            @Override
            public boolean matches(Optional<T> o) {
                if (!o.isPresent()) {
                    return matchOnEmpty;
                } else {
                    return matcher.matches(o.get());
                }
            }
        };
    }
}

@@ -171,49 +171,52 @@
 cher
- %7B%0A%0A    private OptionalMatcher() %7B%7D%0A    
+%3CT%3E implements SpongeMatcher%3COptional%3CT%3E%3E %7B%0A
 %0A   
@@ -621,311 +621,428 @@
 new 
-SpongeMatcher%3COptional%3CT%3E%3E() %7B
+OptionalMatcher%3CT%3E(matcher, matchOnEmpty);
 %0A    
+%7D%0A
     
+%0A
     
-@Override%0A            public boolean matches(Optional%3CT%3E o) %7B
+private boolean matchOnEmpty;
 %0A    
+%0A
     
-        if (!o.isPresent()) %7B%0A                    return matchOnEmpty;%0A                %7D else %7B%0A                    return matcher.matches(o.get());%0A                %7D%0A            %7D%0A        %7D
+private SpongeMatcher%3CT%3E matcher;%0A%0A    private OptionalMatcher(SpongeMatcher%3CT%3E matcher, boolean matchOnEmpty) %7B%0A        this.matcher = matcher;%0A        this.matchOnEmpty = matchOnEmpty;%0A    %7D%0A%0A    @Override%0A    public boolean matches(Optional%3CT%3E o) %7B%0A        return !o.isPresent() ? matchOnEmpty : matcher.matches(o.get())
 ;%0A  

Make the OptionalMatcher a real class