Skip to content

Commit

Permalink
EA-3704 optimise
Browse files Browse the repository at this point in the history
  • Loading branch information
SrishtiSingh-eu committed Jan 30, 2024
1 parent 28e082e commit abdb982
Showing 1 changed file with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,22 @@ public static Set<LanguagePair> getTranslationLanguagePairs(String json, Set<Lan
Iterator<JsonNode> iterator = translate.get(SUPPORTED).iterator();
while (iterator.hasNext()) {
JsonNode object = iterator.next();
Iterator<JsonNode> sources = object.get(SOURCE).iterator();
Iterator<JsonNode> targets = object.get(TARGET).iterator();

List<String> source = new ArrayList<>();
List<String> target = new ArrayList<>();

// get all sources from the object
while (sources.hasNext()) {
source.add(sources.next().asText());
}
// get all target from the object
while (targets.hasNext()) {
target.add(targets.next().asText());
}
List<String> source = getIteratorValue(object.get(SOURCE).iterator());
List<String> target = getIteratorValue(object.get(TARGET).iterator());
// make pairs
source.stream().forEach(v -> target.stream().forEach(t -> translationLanguages.add(new LanguagePair(v, t))));
source.clear();
target.clear();
}
}
}
return translationLanguages;
}

private static List<String> getIteratorValue(Iterator<JsonNode> jsonNodeIterator) {
List<String> values = new ArrayList<>();
// get all sources from the object
while (jsonNodeIterator.hasNext()) {
values.add(jsonNodeIterator.next().asText());
}
return values;
}
}

0 comments on commit abdb982

Please sign in to comment.