@Test public void shouldParseChainProperly() { List<KeyParser> parsersChain = new ArrayList<>(); parsersChain.add(new NoKeyParser<>(PARSER_1)); parsersChain.add(new NoKeyParser<>(PARSER_2)); parsersChain.add(new NoKeyParser<>(PARSER_3)); KeyParser<Object, Integer, UUID> parser = new MultiParser<>(parsersChain); UUID parsed = parser.apply(new Object(), 100); assertNotNull(parsed); }
@Override @NonNull @SuppressWarnings("unchecked") public Parsed apply(@NonNull Key key, @NonNull Raw raw) throws ParserException { Object parsed = raw; for (KeyParser parser : parsers) { try { parsed = parser.apply(key, parsed); } catch (ClassCastException exception) { throw createParserException(); } } return (Parsed) parsed; }
MultiParser implements KeyParser<Key, Raw, Parsed> { @Override @NonNull @SuppressWarnings("unchecked") public Parsed apply(@NonNull Key key, @NonNull Raw raw) throws ParserException { Object parsed = raw; for (KeyParser parser : parsers) { try { parsed = parser.apply(key, parsed); } catch (ClassCastException exception) { throw createParserException(); } } return (Parsed) parsed; } }
MultiParser implements KeyParser<Key, Raw, Parsed> { @Override @NonNull @SuppressWarnings("unchecked") public Parsed apply(@NonNull Key key, @NonNull Raw raw) throws ParserException { Object parsed = raw; for (KeyParser parser : parsers) { try { parsed = parser.apply(key, parsed); } catch (ClassCastException exception) { throw createParserException(); } } return (Parsed) parsed; } MultiParser(List<KeyParser> parsers); }
MultiParser implements KeyParser<Key, Raw, Parsed> { @Override @NonNull @SuppressWarnings("unchecked") public Parsed apply(@NonNull Key key, @NonNull Raw raw) throws ParserException { Object parsed = raw; for (KeyParser parser : parsers) { try { parsed = parser.apply(key, parsed); } catch (ClassCastException exception) { throw createParserException(); } } return (Parsed) parsed; } MultiParser(List<KeyParser> parsers); @Override @NonNull @SuppressWarnings("unchecked") Parsed apply(@NonNull Key key, @NonNull Raw raw); }
MultiParser implements KeyParser<Key, Raw, Parsed> { @Override @NonNull @SuppressWarnings("unchecked") public Parsed apply(@NonNull Key key, @NonNull Raw raw) throws ParserException { Object parsed = raw; for (KeyParser parser : parsers) { try { parsed = parser.apply(key, parsed); } catch (ClassCastException exception) { throw createParserException(); } } return (Parsed) parsed; } MultiParser(List<KeyParser> parsers); @Override @NonNull @SuppressWarnings("unchecked") Parsed apply(@NonNull Key key, @NonNull Raw raw);  }