@Test @DisplayName("Test that single and double quotes strings are working") void testMultipleValues() { final var sut = new CompoundParamsBuilder("abrakadabra alma=\"Hungarian\" alma='German' apple='English' manzana='Espa\\'nol'"); final var cp = sut.build(); Assertions.assertEquals("abrakadabra", cp.id()); Assertions.assertEquals(3, cp.keySet().size()); Assertions.assertEquals("Hungarian", cp.get("alma")); Assertions.assertEquals("English", cp.get("apple")); Assertions.assertEquals("Espa'nol", cp.get("manzana")); Assertions.assertEquals(2, cp.getValueList("alma").size()); Assertions.assertEquals("Hungarian", cp.getValueList("alma").get(0)); Assertions.assertEquals("German", cp.getValueList("alma").get(1)); }
public CompoundParams build() { final Map<String, List<String>> params = new HashMap<>(); final var lexer = new Lexer(); final LexicalElement[] elements; try { elements = lexer.apply(Collections.singletonList(line)); } catch (IllegalArgumentException iae) { throw new GeciException("Cannot parse the line for parameters: " + line, iae); } if (elements.length < 1) { throwMalformed(line); } String name = ""; final int startAt; if (elements[0].type == IDENTIFIER && elements.length < 2 || elements.length > 1 && elements[1].type != SYMBOL) { name = elements[0].lexeme; startAt = 1; } else { startAt = 0; } for (int i = startAt; i < elements.length; i++) { if (elements[i].type != IDENTIFIER) { throwMalformed(line); } final var key = elements[i].lexeme; i++; if (i >= elements.length || !elements[i].type.is(SYMBOL) || !elements[i].lexeme.equals("=")) { throwMalformed(line); } i++; if (i >= elements.length || !elements[i].type.is(STRING, CHARACTER, FLOAT, INTEGER, IDENTIFIER)) { throwMalformed(line); } final var value = elements[i].lexeme; if (redefine && "id".equals(key)) { name = value; } else if ("id".equals(key)) { throw new GeciException("id is not allowed as parameter name in '" + line + "'"); } else if (!excludedKeys.contains(key)) { if (!params.containsKey(key)) { params.put(key, new ArrayList<>()); } params.get(key).add(value); } } return new CompoundParams(name, params); }
CompoundParamsBuilder { public CompoundParams build() { final Map<String, List<String>> params = new HashMap<>(); final var lexer = new Lexer(); final LexicalElement[] elements; try { elements = lexer.apply(Collections.singletonList(line)); } catch (IllegalArgumentException iae) { throw new GeciException("Cannot parse the line for parameters: " + line, iae); } if (elements.length < 1) { throwMalformed(line); } String name = ""; final int startAt; if (elements[0].type == IDENTIFIER && elements.length < 2 || elements.length > 1 && elements[1].type != SYMBOL) { name = elements[0].lexeme; startAt = 1; } else { startAt = 0; } for (int i = startAt; i < elements.length; i++) { if (elements[i].type != IDENTIFIER) { throwMalformed(line); } final var key = elements[i].lexeme; i++; if (i >= elements.length || !elements[i].type.is(SYMBOL) || !elements[i].lexeme.equals("=")) { throwMalformed(line); } i++; if (i >= elements.length || !elements[i].type.is(STRING, CHARACTER, FLOAT, INTEGER, IDENTIFIER)) { throwMalformed(line); } final var value = elements[i].lexeme; if (redefine && "id".equals(key)) { name = value; } else if ("id".equals(key)) { throw new GeciException("id is not allowed as parameter name in '" + line + "'"); } else if (!excludedKeys.contains(key)) { if (!params.containsKey(key)) { params.put(key, new ArrayList<>()); } params.get(key).add(value); } } return new CompoundParams(name, params); } }
CompoundParamsBuilder { public CompoundParams build() { final Map<String, List<String>> params = new HashMap<>(); final var lexer = new Lexer(); final LexicalElement[] elements; try { elements = lexer.apply(Collections.singletonList(line)); } catch (IllegalArgumentException iae) { throw new GeciException("Cannot parse the line for parameters: " + line, iae); } if (elements.length < 1) { throwMalformed(line); } String name = ""; final int startAt; if (elements[0].type == IDENTIFIER && elements.length < 2 || elements.length > 1 && elements[1].type != SYMBOL) { name = elements[0].lexeme; startAt = 1; } else { startAt = 0; } for (int i = startAt; i < elements.length; i++) { if (elements[i].type != IDENTIFIER) { throwMalformed(line); } final var key = elements[i].lexeme; i++; if (i >= elements.length || !elements[i].type.is(SYMBOL) || !elements[i].lexeme.equals("=")) { throwMalformed(line); } i++; if (i >= elements.length || !elements[i].type.is(STRING, CHARACTER, FLOAT, INTEGER, IDENTIFIER)) { throwMalformed(line); } final var value = elements[i].lexeme; if (redefine && "id".equals(key)) { name = value; } else if ("id".equals(key)) { throw new GeciException("id is not allowed as parameter name in '" + line + "'"); } else if (!excludedKeys.contains(key)) { if (!params.containsKey(key)) { params.put(key, new ArrayList<>()); } params.get(key).add(value); } } return new CompoundParams(name, params); } CompoundParamsBuilder(final String line); }
CompoundParamsBuilder { public CompoundParams build() { final Map<String, List<String>> params = new HashMap<>(); final var lexer = new Lexer(); final LexicalElement[] elements; try { elements = lexer.apply(Collections.singletonList(line)); } catch (IllegalArgumentException iae) { throw new GeciException("Cannot parse the line for parameters: " + line, iae); } if (elements.length < 1) { throwMalformed(line); } String name = ""; final int startAt; if (elements[0].type == IDENTIFIER && elements.length < 2 || elements.length > 1 && elements[1].type != SYMBOL) { name = elements[0].lexeme; startAt = 1; } else { startAt = 0; } for (int i = startAt; i < elements.length; i++) { if (elements[i].type != IDENTIFIER) { throwMalformed(line); } final var key = elements[i].lexeme; i++; if (i >= elements.length || !elements[i].type.is(SYMBOL) || !elements[i].lexeme.equals("=")) { throwMalformed(line); } i++; if (i >= elements.length || !elements[i].type.is(STRING, CHARACTER, FLOAT, INTEGER, IDENTIFIER)) { throwMalformed(line); } final var value = elements[i].lexeme; if (redefine && "id".equals(key)) { name = value; } else if ("id".equals(key)) { throw new GeciException("id is not allowed as parameter name in '" + line + "'"); } else if (!excludedKeys.contains(key)) { if (!params.containsKey(key)) { params.put(key, new ArrayList<>()); } params.get(key).add(value); } } return new CompoundParams(name, params); } CompoundParamsBuilder(final String line); CompoundParamsBuilder redefineId(); CompoundParamsBuilder exclude(String... keys); CompoundParams build(); }
CompoundParamsBuilder { public CompoundParams build() { final Map<String, List<String>> params = new HashMap<>(); final var lexer = new Lexer(); final LexicalElement[] elements; try { elements = lexer.apply(Collections.singletonList(line)); } catch (IllegalArgumentException iae) { throw new GeciException("Cannot parse the line for parameters: " + line, iae); } if (elements.length < 1) { throwMalformed(line); } String name = ""; final int startAt; if (elements[0].type == IDENTIFIER && elements.length < 2 || elements.length > 1 && elements[1].type != SYMBOL) { name = elements[0].lexeme; startAt = 1; } else { startAt = 0; } for (int i = startAt; i < elements.length; i++) { if (elements[i].type != IDENTIFIER) { throwMalformed(line); } final var key = elements[i].lexeme; i++; if (i >= elements.length || !elements[i].type.is(SYMBOL) || !elements[i].lexeme.equals("=")) { throwMalformed(line); } i++; if (i >= elements.length || !elements[i].type.is(STRING, CHARACTER, FLOAT, INTEGER, IDENTIFIER)) { throwMalformed(line); } final var value = elements[i].lexeme; if (redefine && "id".equals(key)) { name = value; } else if ("id".equals(key)) { throw new GeciException("id is not allowed as parameter name in '" + line + "'"); } else if (!excludedKeys.contains(key)) { if (!params.containsKey(key)) { params.put(key, new ArrayList<>()); } params.get(key).add(value); } } return new CompoundParams(name, params); } CompoundParamsBuilder(final String line); CompoundParamsBuilder redefineId(); CompoundParamsBuilder exclude(String... keys); CompoundParams build();  }