com.regnosys.rosetta.translate.IngesterGeneratorUtils Maven / Gradle / Ivy
package com.regnosys.rosetta.translate;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import com.regnosys.rosetta.translate.synonymmap.Element;
import com.regnosys.rosetta.translate.synonymmap.SynonymValue;
public class IngesterGeneratorUtils {
/**
* Determines whether the synonym exists or absent condition is predicated on a separate path.
*
* If false the conditional logic is required to do path filtering.
*/
static boolean isConditionalMappingPredicatedOnDifferentPath(List synonymPaths, List conditionSynonymPaths) {
return !toFirstPathElements(synonymPaths).stream()
.anyMatch(p -> toFirstPathElements(conditionSynonymPaths).contains(p));
}
private static List toFirstPathElements(List paths) {
return paths.stream()
.map(SynonymValue::getSynonymPath)
.map(IngesterGeneratorUtils::getFirstItem)
.filter(Optional::isPresent)
.map(Optional::get)
.distinct()
.collect(Collectors.toList());
}
private static Optional getFirstItem(List list) {
Iterator iterator = list.iterator();
return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.empty();
}
}