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

com.turbospaces.logging.ClassUtils Maven / Gradle / Ivy

There is a newer version: 2.0.33
Show newest version
package com.turbospaces.logging;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class ClassUtils {
    private static final Logger logger = LoggerFactory.getLogger(ClassUtils.class);

    private ClassUtils() {
    }

    public static Optional> parseThrowableClass(String classStr) {
        try {
            Class clazz = Class.forName(classStr.trim());
            if (Throwable.class.isAssignableFrom(clazz)) {
                return Optional.of((Class) clazz);
            }
            logger.error("Class is not Throwable: {}", classStr);
        } catch (Exception ex) {
            logger.error("Class can't be parsed: {}", classStr, ex);
        }
        return Optional.empty();
    }

    public static List> parseThrowableClasses(String classesStr, String separator) {
        List> exceptions = new ArrayList<>();
        if (!classesStr.trim().isEmpty()) {
            for (String exClass : classesStr.split(separator)) {
                ClassUtils.parseThrowableClass(exClass).ifPresent(exceptions::add);
            }
        }
        return exceptions;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy