/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
 */
package io.jenetics.internal.util;

import static java.util.Objects.requireNonNull;

import java.net.URL;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * This class contains some common predicates
 *
 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
 * @since 3.0
 * @version 4.3
 */
public final class Predicates {
	private Predicates() {}

	public static final Predicate<Object> TRUE = a -> true;

	/**
	 * Return a predicate, which always return {@code true}.
	 *
	 * @param <T> the predicate type
	 * @return a predicate, which always return {@code true}
	 */
	@SuppressWarnings("unchecked")
	public static <T> Predicate<T> True() {
		return (Predicate<T>)TRUE;
	}


	/**
	 * Checks whether the given {@code throwable} is a non-fatal error.
	 *
	 * @param throwable the throwable to check
	 * @return true if the given {@code throwable} is a non-fatal error
	 */
	public static boolean nonFatal(final Throwable throwable) {
		return
			!(throwable instanceof VirtualMachineError) &&
			!(throwable instanceof ThreadDeath) &&
			!(throwable instanceof InterruptedException) &&
			!(throwable instanceof LinkageError);
	}

	public static <T extends Throwable, R> R
	nonFatal(T t, Function<? super Throwable, ? extends R> block) {
		if (nonFatal(t)) {
			return block.apply(t);
		}

		throw sneakyThrow(t);
	}

	private static RuntimeException sneakyThrow(Throwable t) {
		return sneakyThrow0(requireNonNull(t));
	}

	@SuppressWarnings("unchecked")
	private static <T extends Throwable> T sneakyThrow0(Throwable t) throws T {
		throw (T)t;
	}

	public static void main(final String[] args) {
		try {
			new URL("asdf");
		} catch (NullPointerException e) {
			System.out.println(e);
		} catch (Throwable t) {
			nonFatal(t, error -> {
				return null;
			});
		}
	}

}

@@ -777,114 +777,8 @@
 l;%0A%0A
-import static java.util.Objects.requireNonNull;%0A%0Aimport java.net.URL;%0Aimport java.util.function.Function;%0A
 impo
@@ -1372,1105 +1372,6 @@
 %0A%09%7D%0A
-%0A%0A%09/**%0A%09 * Checks whether the given %7B@code throwable%7D is a non-fatal error.%0A%09 *%0A%09 * @param throwable the throwable to check%0A%09 * @return true if the given %7B@code throwable%7D is a non-fatal error%0A%09 */%0A%09public static boolean nonFatal(final Throwable throwable) %7B%0A%09%09return%0A%09%09%09!(throwable instanceof VirtualMachineError) &&%0A%09%09%09!(throwable instanceof ThreadDeath) &&%0A%09%09%09!(throwable instanceof InterruptedException) &&%0A%09%09%09!(throwable instanceof LinkageError);%0A%09%7D%0A%0A%09public static %3CT extends Throwable, R%3E R%0A%09nonFatal(T t, Function%3C? super Throwable, ? extends R%3E block) %7B%0A%09%09if (nonFatal(t)) %7B%0A%09%09%09return block.apply(t);%0A%09%09%7D%0A%0A%09%09throw sneakyThrow(t);%0A%09%7D%0A%0A%09private static RuntimeException sneakyThrow(Throwable t) %7B%0A%09%09return sneakyThrow0(requireNonNull(t));%0A%09%7D%0A%0A%09@SuppressWarnings(%22unchecked%22)%0A%09private static %3CT extends Throwable%3E T sneakyThrow0(Throwable t) throws T %7B%0A%09%09throw (T)t;%0A%09%7D%0A%0A%09public static void main(final String%5B%5D args) %7B%0A%09%09try %7B%0A%09%09%09new URL(%22asdf%22);%0A%09%09%7D catch (NullPointerException e) %7B%0A%09%09%09System.out.println(e);%0A%09%09%7D catch (Throwable t) %7B%0A%09%09%09nonFatal(t, error -%3E %7B%0A%09%09%09%09return null;%0A%09%09%09%7D);%0A%09%09%7D%0A%09%7D%0A%0A
 %7D%0A

Remove unused methods.