List of usage examples for java.util Objects requireNonNull
public static <T> T requireNonNull(T obj)
From source file:net.maritimecloud.identityregistry.model.database.Role.java
/** Copies this user into the other */ public Role copyTo(Role role) { Objects.requireNonNull(role); role.setId(id);// w w w.ja v a 2 s .c om role.setIdOrganization(idOrganization); role.setPermission(permission); role.setRoleName(roleName); return role; }
From source file:com.conwet.silbops.msg.NotifyMsg.java
public void setNotification(Notification notification) { this.notification = Objects.requireNonNull(notification); }
From source file:com.conwet.silbops.msg.SubscribeMsg.java
public void setSubscription(Subscription subscription) { this.subscription = Objects.requireNonNull(subscription); }
From source file:net.sf.jabref.logic.fulltext.DoiResolution.java
@Override public Optional<URL> findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional<URL> pdfLink = Optional.empty(); Optional<DOI> doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); if (doi.isPresent()) { String sciLink = doi.get().getURIAsASCIIString(); // follow all redirects and scan for a single pdf link if (!sciLink.isEmpty()) { try { Connection connection = Jsoup.connect(sciLink); connection.followRedirects(true); connection.ignoreHttpErrors(true); // some publishers are quite slow (default is 3s) connection.timeout(5000); Document html = connection.get(); // scan for PDF Elements elements = html.body().select("[href]"); List<Optional<URL>> links = new ArrayList<>(); for (Element element : elements) { String href = element.attr("abs:href"); // Only check if pdf is included in the link // See https://github.com/lehner/LocalCopy for scrape ideas if (href.contains("pdf") && MimeTypeDetector.isPdfContentType(href)) { links.add(Optional.of(new URL(href))); }/*from w w w . j av a2 s .co m*/ } // return if only one link was found (high accuracy) if (links.size() == 1) { LOGGER.info("Fulltext PDF found @ " + sciLink); pdfLink = links.get(0); } } catch (IOException e) { LOGGER.warn("DoiResolution fetcher failed: ", e); } } } return pdfLink; }
From source file:net.sf.jabref.logic.fetcher.DoiResolution.java
@Override public Optional<URL> findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional<URL> pdfLink = Optional.empty(); Optional<DOI> doi = DOI.build(entry.getField("doi")); if (doi.isPresent()) { String sciLink = doi.get().getURLAsASCIIString(); // follow all redirects and scan for a single pdf link if (!sciLink.isEmpty()) { try { Connection connection = Jsoup.connect(sciLink); connection.followRedirects(true); connection.ignoreHttpErrors(true); // some publishers are quite slow (default is 3s) connection.timeout(5000); Document html = connection.get(); // scan for PDF Elements elements = html.body().select("[href]"); List<Optional<URL>> links = new ArrayList<>(); for (Element element : elements) { String href = element.attr("abs:href"); // Only check if pdf is included in the link // See https://github.com/lehner/LocalCopy for scrape ideas if (href.contains("pdf") && MimeTypeDetector.isPdfContentType(href)) { links.add(Optional.of(new URL(href))); }//from w w w.j a v a2 s . c o m } // return if only one link was found (high accuracy) if (links.size() == 1) { LOGGER.info("Fulltext PDF found @ " + sciLink); pdfLink = links.get(0); } } catch (IOException e) { LOGGER.warn("DoiResolution fetcher failed: ", e); } } } return pdfLink; }
From source file:com.bodybuilding.argos.discovery.ClusterRegistry.java
@Autowired public ClusterRegistry(ClusterDiscovery clusterDiscovery, HystrixClusterMonitorFactory clusterMonitorFactory) { Objects.requireNonNull(clusterDiscovery); Objects.requireNonNull(clusterMonitorFactory); this.clusterDiscovery = clusterDiscovery; this.clusterMonitorFactory = clusterMonitorFactory; // inspired by com.netflix.turbine.Turbine // https://github.com/Netflix/Turbine/commit/10cd853c912442d5d62278cc98c0fac2f33b65b9#diff-6b51f2ba8d8fc42a4e669d2f34205684R105 Observable<Cluster> clusters = clusterDiscovery.getClusters().share(); Observable<Cluster> clusterAdds = clusters.filter(Cluster::isActive); Observable<Cluster> clusterRemoves = clusters.filter(c -> !c.isActive()); Observable<Observable<HystrixClusterMetrics>> clusterObservables = clusterAdds.map(c -> { if (monitoredClusters.get(c.getName()) != null) { return monitoredClusters.get(c.getName()).observe(); } else {//ww w . ja va 2 s.c o m HystrixClusterMonitor monitor = clusterMonitorFactory.createMonitor(c.getName(), c.getUrl()); monitoredClusters.put(c.getName(), monitor); LOG.info("Started monitoring {} | {}", c.getName(), c.getUrl()); return monitor.observe().takeUntil(clusterRemoves.filter(c2 -> { if (c2.getName().equals(c.getName())) { LOG.info("Stopping monitoring for {} ", c.getName()); return true; } else { return false; } })); } }); mergedMetrics = Observable.mergeDelayError(clusterObservables.retry()).share(); }
From source file:fr.landel.utils.io.FileSystemUtils.java
/** * Replace all special characters in filename by the replacement string. If * replacement is null, the replacement becomes an empty String. * //from ww w .j a va 2 s . co m * @param filename * The input filename * @param replacement * The replacement string * @return The filename processed * @throws NullPointerException * if filename is {@code null} */ public static String replaceSpecialCharacters(final String filename, final String replacement) { Objects.requireNonNull(filename); if (replacement != null) { return PATTERN_SPECIAL_CHARACTERS.matcher(filename).replaceAll(replacement); } return PATTERN_SPECIAL_CHARACTERS.matcher(filename).replaceAll(""); }
From source file:net.sf.jabref.gui.worker.VersionWorker.java
public VersionWorker(JabRefFrame mainFrame, boolean manualExecution, Version installedVersion, Version toBeIgnored) {//from w w w . j a v a 2s. c om this.mainFrame = Objects.requireNonNull(mainFrame); this.manualExecution = manualExecution; this.installedVersion = Objects.requireNonNull(installedVersion); this.toBeIgnored = Objects.requireNonNull(toBeIgnored); }
From source file:org.eclipse.hono.example.AbstractExampleClient.java
@Autowired public final void setHonoClient(final HonoClient client) { this.client = Objects.requireNonNull(client); }
From source file:io.lavagna.service.importexport.FileUpload.java
@Override void process(EventFull e, Event event, Date time, User user, ImportContext context, Path tempFile) { try {/*from ww w . j ava 2s .c o m*/ Path p = Objects.requireNonNull(Read.readFile("files/" + e.getContent(), tempFile)); CardDataUploadContentInfo fileData = Read.readObject("files/" + e.getContent() + ".json", tempFile, new TypeToken<CardDataUploadContentInfo>() { }); ImmutablePair<Boolean, CardData> res = cardDataService.createFile(event.getValueString(), e.getContent(), fileData.getSize(), cardId(e), Files.newInputStream(p), fileData.getContentType(), user, time); if (res.getLeft()) { context.getFileId().put(event.getDataId(), res.getRight().getId()); } Files.delete(p); } catch (IOException ioe) { throw new IllegalStateException("error while handling event FILE_UPLOAD for event: " + e, ioe); } }