use of java.util.Objects in project sonarqube by SonarSource.
the class OneIssuePerDirectorySensor method analyse.
private static void analyse(SensorContext context) {
FileSystem fs = context.fileSystem();
FilePredicates p = fs.predicates();
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
StreamSupport.stream(fs.inputFiles(p.hasType(Type.MAIN)).spliterator(), false).map(file -> fs.inputDir(file.file().getParentFile())).filter(Objects::nonNull).distinct().forEach(inputDir -> {
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(inputDir).message("This issue is generated for any non-empty directory")).save();
});
}
use of java.util.Objects in project jersey by jersey.
the class FeedDownloadTask method run.
@Override
public void run() {
CombinedFeed fetchedCombinedFeed = datastore.get(combinedFeedID, CombinedFeed.class);
if (fetchedCombinedFeed == null) {
LOG.warn("There is no CombinedFeed for the ID: " + combinedFeedID);
return;
}
List<FeedEntry> entries = fetchedCombinedFeed.getUrls().stream().map(feedDownloader).flatMap(Collection::stream).map(entryMapper).filter(Objects::nonNull).sorted((e1, e2) -> e2.getPublishDate().compareTo(e1.getPublishDate())).collect(Collectors.toList());
CombinedFeed combinedFeed = of(fetchedCombinedFeed).feedEntries(entries).build();
datastore.put(combinedFeedID, combinedFeed);
LOG.debug("New entries for the CombinedFeed were downloaded [combined-feed={}, entries-count={}]", combinedFeed.getId(), entries.size());
}
use of java.util.Objects in project presto by prestodb.
the class NodeScheduler method toWhenHasSplitQueueSpaceFuture.
public static ListenableFuture<?> toWhenHasSplitQueueSpaceFuture(Set<Node> blockedNodes, List<RemoteTask> existingTasks, int spaceThreshold) {
if (blockedNodes.isEmpty()) {
return immediateFuture(null);
}
Map<String, RemoteTask> nodeToTaskMap = new HashMap<>();
for (RemoteTask task : existingTasks) {
nodeToTaskMap.put(task.getNodeId(), task);
}
List<ListenableFuture<?>> blockedFutures = blockedNodes.stream().map(Node::getNodeIdentifier).map(nodeToTaskMap::get).filter(Objects::nonNull).map(remoteTask -> remoteTask.whenSplitQueueHasSpace(spaceThreshold)).collect(toImmutableList());
if (blockedFutures.isEmpty()) {
return immediateFuture(null);
}
return whenAnyComplete(blockedFutures);
}
use of java.util.Objects in project requery by requery.
the class EntityType method builderType.
@Override
public Optional<TypeMirror> builderType() {
Optional<Entity> entityAnnotation = annotationOf(Entity.class);
if (entityAnnotation.isPresent()) {
Entity entity = entityAnnotation.get();
Elements elements = processingEnvironment.getElementUtils();
TypeMirror mirror = null;
try {
// easiest way to get the class TypeMirror
Class<?> builderClass = entity.builder();
if (builderClass != void.class) {
mirror = elements.getTypeElement(builderClass.getName()).asType();
}
} catch (MirroredTypeException typeException) {
mirror = typeException.getTypeMirror();
}
if (mirror != null && mirror.getKind() != TypeKind.VOID) {
return Optional.of(mirror);
}
}
if (builderFactoryMethod().isPresent()) {
return Optional.of(builderFactoryMethod().get().getReturnType());
}
return ElementFilter.typesIn(element().getEnclosedElements()).stream().filter(element -> element.getSimpleName().toString().contains("Builder")).map(Element::asType).filter(Objects::nonNull).filter(type -> type.getKind() != TypeKind.VOID).findFirst();
}
use of java.util.Objects in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapter method getExceptionHandlerMethod.
private InvocableHandlerMethod getExceptionHandlerMethod(Throwable ex, HandlerMethod handlerMethod) {
Class<?> handlerType = handlerMethod.getBeanType();
ExceptionHandlerMethodResolver resolver = this.exceptionHandlerCache.computeIfAbsent(handlerType, ExceptionHandlerMethodResolver::new);
return Optional.ofNullable(resolver.resolveMethodByThrowable(ex)).map(method -> createHandlerMethod(handlerMethod.getBean(), method)).orElseGet(() -> this.exceptionHandlerAdviceCache.entrySet().stream().map(entry -> {
if (entry.getKey().isApplicableToBeanType(handlerType)) {
Method method = entry.getValue().resolveMethodByThrowable(ex);
if (method != null) {
Object bean = entry.getKey().resolveBean();
return createHandlerMethod(bean, method);
}
}
return null;
}).filter(Objects::nonNull).findFirst().orElse(null));
}
Aggregations