private Map<String, Integer> collectSections(Iterator<JsonNode> iterator) { Map<String, Integer> sectionsMap = new HashMap<>(); while (iterator.hasNext()) { JsonNode element = iterator.next(); sectionsMap.put(element.get(LINE).asText(), element.get(INDEX).asInt()); } return sectionsMap; }
public Integer extractSectionIndex(JsonNode sections, String seasonNumber) throws ParseException { Map<String, Integer> sectionsList = extractSectionsList(sections); for (Map.Entry<String, Integer> section : sectionsList.entrySet()) { if (matchNumberedSection(section.getKey(), seasonNumber)) { return section.getValue(); } } for (Map.Entry<String, Integer> section : sectionsList.entrySet()) { if (section.getKey().matches(EPISODES)) { return section.getValue(); } } throw new ParseException("Section not found.", 0); }