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

com.smartnews.jpa_entity_generator.rule.TableMatcher 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 table name.
 */
public interface TableMatcher {

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

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

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

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

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

        return false;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy