/**
 * 
 */
package com.github.phantomthief.util;

import java.util.HashSet;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * @author w.vela
 */
public final class MorePredicates {

    private MorePredicates() {
        throw new UnsupportedOperationException();
    }

    public static <T> Predicate<T> distinctUsing(Function<T, Object> mapper) {
        return new Predicate<T>() {

            private final Set<Object> set = new HashSet<>();

            @Override
            public boolean test(T t) {
                return set.add(mapper.apply(t));
            }
        };
    }

    public static <T> Predicate<T> afterElement(T element) {
        return afterElement(element, true);
    }

    public static <T> Predicate<T> afterElement(T element, boolean inclusive) {
        return after(e -> Objects.equals(element, e), inclusive);
    }

    public static <T> Predicate<T> after(Predicate<T> predicate) {
        return after(predicate, true);
    }

    public static <T> Predicate<T> after(Predicate<T> predicate, boolean inclusive) {
        return new Predicate<T>() {

            private boolean started;

            @Override
            public boolean test(T t) {
                if (started) {
                    return true;
                } else {
                    if (predicate.test(t)) {
                        started = true;
                        if (inclusive) {
                            return true;
                        }
                    }
                    return false;
                }
            }
        };
    }

    public static <T> Predicate<T> probability(double probability) {
        return new Predicate<T>() {

            private final Random random = new Random();

            @Override
            public boolean test(T t) {
                return random.nextDouble() <= probability;
            }
        };
    }
}

@@ -139,24 +139,60 @@
 a.util.Set;%0A
+import java.util.function.Consumer;%0A
 import java.
@@ -397,32 +397,325 @@
 ption();%0A    %7D%0A%0A
+    public static %3CT%3E Predicate%3CT%3E ifNot(Predicate%3CT%3E predicate, Consumer%3CT%3E negateConsumer) %7B%0A        return t -%3E %7B%0A            boolean result = predicate.test(t);%0A            if (!result) %7B%0A                negateConsumer.accept(t);%0A            %7D%0A            return result;%0A        %7D;%0A    %7D%0A%0A
     public stati

add ifNot for fail consume.