@Test public void testIntegerQuery() { Configuration config = Configuration.current(); ConvertQuery<Integer> converter = new ConvertQuery<>("101", TypeLiteral.of(Integer.class)); Integer result = converter.apply(config); assertThat(result.longValue()).isEqualTo(101); }
@Override public T apply(Configuration config) { List<PropertyConverter<T>> converters = config.getContext().getPropertyConverters(type); ConversionContext context = new ConversionContext.Builder(type).setConfiguration(config) .setKey(ConvertQuery.class.getName()).build(); for (PropertyConverter<?> conv : converters) { try { if (conv instanceof OptionalConverter) { continue; } T result = (T) conv.convert(rawValue, context); if (result != null) { return result; } } catch (Exception e) { LOG.log(Level.FINEST, e, () -> "Converter " + conv + " failed to convert to " + type); } } return null; }
ConvertQuery implements Function<Configuration, T> { @Override public T apply(Configuration config) { List<PropertyConverter<T>> converters = config.getContext().getPropertyConverters(type); ConversionContext context = new ConversionContext.Builder(type).setConfiguration(config) .setKey(ConvertQuery.class.getName()).build(); for (PropertyConverter<?> conv : converters) { try { if (conv instanceof OptionalConverter) { continue; } T result = (T) conv.convert(rawValue, context); if (result != null) { return result; } } catch (Exception e) { LOG.log(Level.FINEST, e, () -> "Converter " + conv + " failed to convert to " + type); } } return null; } }
ConvertQuery implements Function<Configuration, T> { @Override public T apply(Configuration config) { List<PropertyConverter<T>> converters = config.getContext().getPropertyConverters(type); ConversionContext context = new ConversionContext.Builder(type).setConfiguration(config) .setKey(ConvertQuery.class.getName()).build(); for (PropertyConverter<?> conv : converters) { try { if (conv instanceof OptionalConverter) { continue; } T result = (T) conv.convert(rawValue, context); if (result != null) { return result; } } catch (Exception e) { LOG.log(Level.FINEST, e, () -> "Converter " + conv + " failed to convert to " + type); } } return null; } ConvertQuery(String rawValue, TypeLiteral<T> type); }
ConvertQuery implements Function<Configuration, T> { @Override public T apply(Configuration config) { List<PropertyConverter<T>> converters = config.getContext().getPropertyConverters(type); ConversionContext context = new ConversionContext.Builder(type).setConfiguration(config) .setKey(ConvertQuery.class.getName()).build(); for (PropertyConverter<?> conv : converters) { try { if (conv instanceof OptionalConverter) { continue; } T result = (T) conv.convert(rawValue, context); if (result != null) { return result; } } catch (Exception e) { LOG.log(Level.FINEST, e, () -> "Converter " + conv + " failed to convert to " + type); } } return null; } ConvertQuery(String rawValue, TypeLiteral<T> type); @Override T apply(Configuration config); }
ConvertQuery implements Function<Configuration, T> { @Override public T apply(Configuration config) { List<PropertyConverter<T>> converters = config.getContext().getPropertyConverters(type); ConversionContext context = new ConversionContext.Builder(type).setConfiguration(config) .setKey(ConvertQuery.class.getName()).build(); for (PropertyConverter<?> conv : converters) { try { if (conv instanceof OptionalConverter) { continue; } T result = (T) conv.convert(rawValue, context); if (result != null) { return result; } } catch (Exception e) { LOG.log(Level.FINEST, e, () -> "Converter " + conv + " failed to convert to " + type); } } return null; } ConvertQuery(String rawValue, TypeLiteral<T> type); @Override T apply(Configuration config);  }