use of java.util.stream.Stream.of in project component-runtime by Talend.
the class ComponentValidator method validateInternationalization.
private void validateInternationalization(final AnnotationFinder finder, final List<Class<?>> components, final Set<String> errors) {
errors.addAll(components.stream().map(this::validateComponentResourceBundle).filter(Objects::nonNull).collect(toList()));
errors.addAll(finder.findAnnotatedFields(Option.class).stream().map(Field::getType).filter(Class::isEnum).distinct().flatMap(enumType -> Stream.of(enumType.getFields()).filter(f -> Modifier.isStatic(f.getModifiers()) && Modifier.isFinal(f.getModifiers())).filter(f -> {
final ResourceBundle bundle = ofNullable(findResourceBundle(enumType)).orElseGet(() -> findResourceBundle(f.getDeclaringClass()));
final String key = enumType.getSimpleName() + "." + f.getName() + "._displayName";
return bundle == null || !bundle.containsKey(key);
}).map(f -> "Missing key " + enumType.getSimpleName() + "." + f.getName() + "._displayName in " + enumType + " resource bundle")).collect(toSet()));
for (final Class<?> i : finder.findAnnotatedClasses(Internationalized.class)) {
final ResourceBundle resourceBundle = findResourceBundle(i);
if (resourceBundle != null) {
final Collection<String> keys = of(i.getMethods()).filter(m -> m.getDeclaringClass() != Object.class).map(m -> i.getName() + "." + m.getName()).collect(toSet());
errors.addAll(keys.stream().filter(k -> !resourceBundle.containsKey(k)).map(k -> "Missing key " + k + " in " + i + " resource bundle").collect(toList()));
errors.addAll(resourceBundle.keySet().stream().filter(k -> k.startsWith(i.getName() + ".") && !keys.contains(k)).map(k -> "Key " + k + " from " + i + " is no more used").collect(toList()));
} else {
errors.add("No resource bundle for " + i);
}
}
}
Aggregations