void add(ConfigMapperProvider provider) { add(genericType -> { // first try to get it from generic type mappers map BiFunction<Config, ConfigMapper, ?> converter = provider.genericTypeMappers().get(genericType); if (null != converter) { return Optional.of(converter); } // second try to get it from generic type method Optional<? extends BiFunction<Config, ConfigMapper, ?>> mapper1 = provider.mapper(genericType); if (mapper1.isPresent()) { return mapper1; } if (!genericType.isClass()) { return Optional.empty(); } // third try the specific class map Class<?> rawType = genericType.rawType(); Function<Config, ?> configConverter = provider.mappers().get(rawType); if (null != configConverter) { return Optional.of((config, mapper) -> configConverter.apply(config)); } // and last, the specific class method return provider.mapper(rawType) .map(funct -> (config, mapper) -> funct.apply(config)); }); }
void add(ConfigMapperProvider provider) { add(genericType -> { // first try to get it from generic type mappers map BiFunction<Config, ConfigMapper, ?> converter = provider.genericTypeMappers().get(genericType); if (null != converter) { return Optional.of(converter); } // second try to get it from generic type method Optional<? extends BiFunction<Config, ConfigMapper, ?>> mapper1 = provider.mapper(genericType); if (mapper1.isPresent()) { return mapper1; } if (!genericType.isClass()) { return Optional.empty(); } // third try the specific class map Class<?> rawType = genericType.rawType(); Function<Config, ?> configConverter = provider.mappers().get(rawType); if (null != configConverter) { return Optional.of((config, mapper) -> configConverter.apply(config)); } // and last, the specific class method return provider.mapper(rawType) .map(funct -> (config, mapper) -> funct.apply(config)); }); }