@Test public void testFindConverter_NotFound() { Assertions.assertThrows(IllegalArgumentException.class, () -> { new LinkkiConverterRegistry().findConverter(String.class, java.time.LocalDate.class); }); }
@SuppressWarnings("unchecked") public <P, M> Converter<P, M> findConverter(Type presentationType, Type modelType) { Class<?> rawPresentationType = getRawType(presentationType); Class<?> rawModelType = getRawType(modelType); if (isIdentityNecessary(rawPresentationType, rawModelType)) { return (Converter<P, M>)Converter.identity(); } else { return converters.computeIfAbsent(rawPresentationType, t -> Sequence.empty()) .stream() .map(Converter.class::cast) .filter(c -> TypeUtils.equals(getPresentationType(c), rawPresentationType) && TypeUtils.equals(rawModelType, getModelType(c))) .findFirst() .orElseThrow(() -> new IllegalArgumentException( "Cannot convert presentation type " + rawPresentationType + " to model type " + rawModelType)); } }
LinkkiConverterRegistry implements Serializable { @SuppressWarnings("unchecked") public <P, M> Converter<P, M> findConverter(Type presentationType, Type modelType) { Class<?> rawPresentationType = getRawType(presentationType); Class<?> rawModelType = getRawType(modelType); if (isIdentityNecessary(rawPresentationType, rawModelType)) { return (Converter<P, M>)Converter.identity(); } else { return converters.computeIfAbsent(rawPresentationType, t -> Sequence.empty()) .stream() .map(Converter.class::cast) .filter(c -> TypeUtils.equals(getPresentationType(c), rawPresentationType) && TypeUtils.equals(rawModelType, getModelType(c))) .findFirst() .orElseThrow(() -> new IllegalArgumentException( "Cannot convert presentation type " + rawPresentationType + " to model type " + rawModelType)); } } }
LinkkiConverterRegistry implements Serializable { @SuppressWarnings("unchecked") public <P, M> Converter<P, M> findConverter(Type presentationType, Type modelType) { Class<?> rawPresentationType = getRawType(presentationType); Class<?> rawModelType = getRawType(modelType); if (isIdentityNecessary(rawPresentationType, rawModelType)) { return (Converter<P, M>)Converter.identity(); } else { return converters.computeIfAbsent(rawPresentationType, t -> Sequence.empty()) .stream() .map(Converter.class::cast) .filter(c -> TypeUtils.equals(getPresentationType(c), rawPresentationType) && TypeUtils.equals(rawModelType, getModelType(c))) .findFirst() .orElseThrow(() -> new IllegalArgumentException( "Cannot convert presentation type " + rawPresentationType + " to model type " + rawModelType)); } } @SafeVarargs  LinkkiConverterRegistry(Converter<?, ?>... customConverters);  LinkkiConverterRegistry(Collection<Converter<?, ?>> customConverters);  LinkkiConverterRegistry(Sequence<Converter<?, ?>> customConverters); }
LinkkiConverterRegistry implements Serializable { @SuppressWarnings("unchecked") public <P, M> Converter<P, M> findConverter(Type presentationType, Type modelType) { Class<?> rawPresentationType = getRawType(presentationType); Class<?> rawModelType = getRawType(modelType); if (isIdentityNecessary(rawPresentationType, rawModelType)) { return (Converter<P, M>)Converter.identity(); } else { return converters.computeIfAbsent(rawPresentationType, t -> Sequence.empty()) .stream() .map(Converter.class::cast) .filter(c -> TypeUtils.equals(getPresentationType(c), rawPresentationType) && TypeUtils.equals(rawModelType, getModelType(c))) .findFirst() .orElseThrow(() -> new IllegalArgumentException( "Cannot convert presentation type " + rawPresentationType + " to model type " + rawModelType)); } } @SafeVarargs  LinkkiConverterRegistry(Converter<?, ?>... customConverters);  LinkkiConverterRegistry(Collection<Converter<?, ?>> customConverters);  LinkkiConverterRegistry(Sequence<Converter<?, ?>> customConverters); @SuppressWarnings("unchecked") Converter<P, M> findConverter(Type presentationType, Type modelType); LinkkiConverterRegistry with(Converter<?, ?> converter); static LinkkiConverterRegistry getCurrent(); }
LinkkiConverterRegistry implements Serializable { @SuppressWarnings("unchecked") public <P, M> Converter<P, M> findConverter(Type presentationType, Type modelType) { Class<?> rawPresentationType = getRawType(presentationType); Class<?> rawModelType = getRawType(modelType); if (isIdentityNecessary(rawPresentationType, rawModelType)) { return (Converter<P, M>)Converter.identity(); } else { return converters.computeIfAbsent(rawPresentationType, t -> Sequence.empty()) .stream() .map(Converter.class::cast) .filter(c -> TypeUtils.equals(getPresentationType(c), rawPresentationType) && TypeUtils.equals(rawModelType, getModelType(c))) .findFirst() .orElseThrow(() -> new IllegalArgumentException( "Cannot convert presentation type " + rawPresentationType + " to model type " + rawModelType)); } } @SafeVarargs  LinkkiConverterRegistry(Converter<?, ?>... customConverters);  LinkkiConverterRegistry(Collection<Converter<?, ?>> customConverters);  LinkkiConverterRegistry(Sequence<Converter<?, ?>> customConverters); @SuppressWarnings("unchecked") Converter<P, M> findConverter(Type presentationType, Type modelType); LinkkiConverterRegistry with(Converter<?, ?> converter); static LinkkiConverterRegistry getCurrent(); static final LinkkiConverterRegistry DEFAULT; }