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

fr.ouestfrance.querydsl.postgrest.mappers.InMapper Maven / Gradle / Ivy

The newest version!
package fr.ouestfrance.querydsl.postgrest.mappers;

import java.util.Collection;
import java.util.stream.Collectors;

import fr.ouestfrance.querydsl.FilterOperation;
import fr.ouestfrance.querydsl.postgrest.model.Filter;
import fr.ouestfrance.querydsl.postgrest.model.exceptions.PostgrestRequestException;
import fr.ouestfrance.querydsl.postgrest.model.impl.QueryFilter;


/**
 * Concrete mapping for in list
 */
public class InMapper extends AbstractMapper {

    @Override
    public Filter getFilter(String field, Object value) {
        if (value instanceof Collection col) {
            return QueryFilter.of(field, Operators.IN, "(" + col.stream().map(Object::toString).collect(Collectors.joining(",")) + ")");
        }
        throw new PostgrestRequestException("Filter " + operation() + " should be on Collection type but was " + value.getClass().getSimpleName());
    }


    @Override
    public Class operation() {
        return FilterOperation.IN.class;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy