Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: removed complex method smell by reducing cyclomatic complexity of toQueryConfig function in QueryOption class #314

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,63 +68,86 @@ public class QueryOption implements CliOption {
@CommandLine.ArgGroup
private XMLQueryOption xmlQueryOption;

public QueryConfig toQueryConfig() {
if (typeNamesOption != null
|| featureVersionOption != null
|| resourceIdOption != null
|| databaseIdOption != null
|| boundingBoxOption != null
|| counterOption != null
|| sqlSelectOption != null) {
QueryConfig queryConfig = new QueryConfig();
List<AbstractPredicate> predicates = new ArrayList<>();

if (typeNamesOption != null) {
queryConfig.setFeatureTypeFilter(typeNamesOption.toFeatureTypeFilter());
}
private void addFeatureTypeFilter(QueryConfig queryConfig) {
if (typeNamesOption != null) {
queryConfig.setFeatureTypeFilter(typeNamesOption.toFeatureTypeFilter());
}
}

SimpleFeatureVersionFilter versionFilter = featureVersionOption != null ?
featureVersionOption.toFeatureVersionFilter() :
FeatureVersionOption.defaultFeatureVersionFilter();
private void addVersionFilter(QueryConfig queryOption, List<AbstractPredicate> predicates) {
SimpleFeatureVersionFilter versionFilter = featureVersionOption != null ?
featureVersionOption.toFeatureVersionFilter() :
FeatureVersionOption.defaultFeatureVersionFilter();

if (versionFilter != null) {
AbstractPredicate predicate = versionFilter.toPredicate();
if (predicate != null) {
predicates.add(predicate);
}
if (versionFilter != null) {
AbstractPredicate predicate = versionFilter.toPredicate();
if (predicate != null) {
predicates.add(predicate);
}
}
}

if (resourceIdOption != null) {
ResourceIdOperator idOperator = resourceIdOption.toResourceIdOperator();
if (idOperator != null) {
predicates.add(idOperator);
}
private void addResourceIdOperator(List<AbstractPredicate> predicates) {
if (resourceIdOption != null) {
ResourceIdOperator idOperator = resourceIdOption.toResourceIdOperator();
if (idOperator != null) {
predicates.add(idOperator);
}
}
}

if (databaseIdOption != null) {
DatabaseIdOperator idOperator = databaseIdOption.toDatabaseIdOperator();
if (idOperator != null) {
predicates.add(idOperator);
}
private void addDatabaseIdOption(List<AbstractPredicate> predicates) {
if (databaseIdOption != null) {
DatabaseIdOperator idOperator = databaseIdOption.toDatabaseIdOperator();
if (idOperator != null) {
predicates.add(idOperator);
}
}
}

if (boundingBoxOption != null) {
AbstractSpatialOperator spatialOperator = boundingBoxOption.toSpatialOperator();
if (spatialOperator != null) {
predicates.add(spatialOperator);
}
private void addBoundingBoxOptionPredicates(List<AbstractPredicate> predicates) {
if (boundingBoxOption != null) {
AbstractSpatialOperator spatialOperator = boundingBoxOption.toSpatialOperator();
if (spatialOperator != null) {
predicates.add(spatialOperator);
}
}
}

if (counterOption != null) {
queryConfig.setCounterFilter(counterOption.toCounterFilter());
}
private void addCounterOptionFilter(QueryConfig queryConfig) {
if (counterOption != null) {
queryConfig.setCounterFilter(counterOption.toCounterFilter());
}
}

if (sqlSelectOption != null) {
SelectOperator selectOperator = sqlSelectOption.toSelectOperator();
if (selectOperator != null) {
predicates.add(selectOperator);
}
private void addSqlSelectPredicates(List<AbstractPredicate> predicates) {
if (sqlSelectOption != null) {
SelectOperator selectOperator = sqlSelectOption.toSelectOperator();
if (selectOperator != null) {
predicates.add(selectOperator);
}
}
}

public QueryConfig toQueryConfig() {
if (typeNamesOption != null
|| featureVersionOption != null
|| resourceIdOption != null
|| databaseIdOption != null
|| boundingBoxOption != null
|| counterOption != null
|| sqlSelectOption != null) {
QueryConfig queryConfig = new QueryConfig();
List<AbstractPredicate> predicates = new ArrayList<>();

addFeatureTypeFilter(queryConfig);
addVersionFilter(queryConfig, predicates);
addResourceIdOperator(predicates);
addDatabaseIdOption(predicates);
addBoundingBoxOptionPredicates(predicates);
addCounterOptionFilter(queryConfig);
addSqlSelectPredicates(predicates);


if (!predicates.isEmpty()) {
AndOperator andOperator = new AndOperator();
Expand Down