All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.core.throwable.ThrowableCauseTester Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.core.throwable;

import java.util.function.Predicate;

/**
 * Checks if a {@link Throwable} is caused by given {@link Throwable} class.
 *
 * @author Oliver Richers
 */
public class ThrowableCauseTester implements Predicate {

	private final Class throwableClass;

	public ThrowableCauseTester(Class throwableClass) {

		this.throwableClass = throwableClass;
	}

	@Override
	public boolean test(Throwable throwable) {

		if (throwableClass.isInstance(throwable)) {
			return true;
		} else {
			Throwable cause = throwable.getCause();
			if (cause != null) {
				return test(cause);
			} else {
				return false;
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy