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

com.smartnews.jpa_entity_generator.rule.ClassMatcher Maven / Gradle / Ivy

There is a newer version: 0.99.9
Show newest version
package com.smartnews.jpa_entity_generator.rule;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * Provides #matches method to check if this rule matches a given class name.
 */
public interface ClassMatcher {

    /**
     * Returns a single partial-matching rule.
     */
    String getClassName();

    /**
     * Returns multiple partial-matching rules.
     */
    List getClassNames();

    /**
     * Predicates if the rule this class holds matches a given class name.
     * @param className class name
     * @return true if the rule matches.
     */
    default boolean matches(String className) {
        if (StringUtils.isEmpty(getClassName()) && (getClassNames() == null || getClassNames().size() == 0)) {
            // global settings
            return true;
        }

        String singleTarget = getClassName();
        if (singleTarget != null) {
            boolean matched = singleTarget.equals(className) || className.matches(singleTarget);
            if (matched) {
                return true;
            }
        }

        List targets = getClassNames();
        if (targets != null && targets.isEmpty() == false) {
            boolean matched = targets.contains(className);
            if (matched) {
                return true;
            } else {
                for (String target : targets) {
                    if (className.matches(target)) {
                        return true;
                    }
                }
            }
        }

        return false;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy