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

io.github.perplexhub.rsql.RSQLComplexConverter Maven / Gradle / Ivy

There is a newer version: 6.0.23
Show newest version
package io.github.perplexhub.rsql;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;

import cz.jirutka.rsql.parser.ast.AndNode;
import cz.jirutka.rsql.parser.ast.ComparisonNode;
import cz.jirutka.rsql.parser.ast.ComparisonOperator;
import cz.jirutka.rsql.parser.ast.OrNode;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RSQLComplexConverter extends RSQLVisitorBase>> {

	public RSQLComplexConverter() {
		super();
	}

	@Override
	public Void visit(ComparisonNode node, Map> map) {
		log.debug("visit(node:{},map:{})", node, map);
		String key = node.getSelector();
		ComparisonOperator operator = node.getOperator();
		MultiValueMap operatorMap = map.computeIfAbsent(key, k -> CollectionUtils.toMultiValueMap(new HashMap<>()));
		for (String ops : operator.getSymbols()) {
			operatorMap.addAll(ops, node.getArguments());
		}
		return null;
	}

	@Override
	public Void visit(AndNode node, Map> map) {
		log.debug("visit(node:{},map:{})", node, map);
		node.getChildren().forEach(n -> n.accept(this, map));
		return null;
	}

	@Override
	public Void visit(OrNode node, Map> map) {
		log.debug("visit(node:{},map:{})", node, map);
		node.getChildren().forEach(n -> n.accept(this, map));
		return null;
	}

	@Override
	public Map getPropertyPathMapper() {
		return Collections.emptyMap();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy