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

com.kidsoncoffee.cheesecakes.runner.parameter.converter.DefaultConverterExtractor Maven / Gradle / Ivy

package com.kidsoncoffee.cheesecakes.runner.parameter.converter;

import com.kidsoncoffee.cheesecakes.Parameter;

import java.util.Comparator;
import java.util.List;
import java.util.Optional;

/**
 * Provides an implementation of {@link ParameterConverterExtractor} that extracts {@link
 * Parameter.Converter}s from a list of {@link Parameter.Schema}s matching a set of {@link
 * Parameter.RegistrableConverter}s.
 *
 * 

These converters are considered default because they deal with usual Java language * transformations. * * @author fernando.chovich * @since 1.0 */ public class DefaultConverterExtractor implements ParameterConverterExtractor> { /** The list of default converters. */ private final List defaultConverters; /** * Constructs the extract with a list of default converters. * * @param defaultConverters The list to pull the converters from. */ public DefaultConverterExtractor(final List defaultConverters) { this.defaultConverters = defaultConverters; } /** * Extracts an array of {@link Parameter.Converter} optionals from the list of {@link * Parameter.Schema}. The array returned is the same size of the given list of {@link * Parameter.Schema}s. If the {@link Parameter.Schema#getType()} does not match any converter an * empty optional is assigned to the respective position in the array. * * @param schemas The schemas to extract the converters from. * @return An array of converter optionals. */ @Override public Optional[] extract(final List schemas) { return schemas.stream() .sorted(Comparator.comparingInt(Parameter.Schema::getOverallOrder)) .map( schema -> this.defaultConverters.stream().filter(c -> c.test(schema.getType())).findFirst()) .toArray(Optional[]::new); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy