Skip to content

Commit

Permalink
refactor: removed complex method smell by reducing cyclomatic complex…
Browse files Browse the repository at this point in the history
…ity of toQueryConfig function in QueryOption class
  • Loading branch information
MeetMaratha committed Nov 27, 2024
1 parent 94814b1 commit 9654084
Showing 1 changed file with 68 additions and 45 deletions.
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

0 comments on commit 9654084

Please sign in to comment.