List of usage examples for java.util Objects requireNonNull
public static <T> T requireNonNull(T obj)
From source file:io.github.retz.protocol.data.Application.java
@JsonCreator public Application(@JsonProperty(value = "appid", required = true) String appid, @JsonProperty("persistentFiles") List<String> persistentFiles, @JsonProperty("largeFiles") List<String> largeFiles, @JsonProperty("files") List<String> files, @JsonProperty("diskMB") Optional<Integer> diskMB, @JsonProperty("user") Optional<String> user, @JsonProperty(value = "owner", required = true) String owner, @JsonProperty("container") Container container, @JsonProperty("enabled") boolean enabled) { this.appid = Objects.requireNonNull(appid); this.persistentFiles = persistentFiles; this.largeFiles = (largeFiles == null) ? Arrays.asList() : largeFiles; this.files = (files == null) ? Arrays.asList() : files; this.diskMB = diskMB; this.owner = Objects.requireNonNull(owner); this.user = user; this.container = (container != null) ? container : new MesosContainer(); this.enabled = enabled; }
From source file:com.graphaware.common.util.PropertyContainerUtils.java
/** * Get ID from a {@link org.neo4j.graphdb.PropertyContainer}. * * @param propertyContainer to get ID from. Must be a {@link org.neo4j.graphdb.Node} or {@link org.neo4j.graphdb.Relationship}. Must not be <code>null</code>. * @return ID// w w w . j a v a2 s . c o m * @throws IllegalStateException in case the propertyContainer is not a {@link org.neo4j.graphdb.Node} or a {@link org.neo4j.graphdb.Relationship}. */ public static long id(PropertyContainer propertyContainer) { Objects.requireNonNull(propertyContainer); if (Node.class.isAssignableFrom(propertyContainer.getClass())) { return ((Node) propertyContainer).getId(); } if (Relationship.class.isAssignableFrom(propertyContainer.getClass())) { return ((Relationship) propertyContainer).getId(); } throw new IllegalStateException("Unknown Property Container: " + propertyContainer.getClass().getName()); }
From source file:org.eclipse.hono.service.registration.RegistrationHttpEndpoint.java
/** * Creates an endpoint for a Vertx instance. * /* w ww . j av a 2 s.com*/ * @param vertx The Vertx instance to use. * @throws NullPointerException if vertx is {@code null}; */ @Autowired public RegistrationHttpEndpoint(final Vertx vertx) { super(Objects.requireNonNull(vertx)); }
From source file:net.sf.jabref.logic.fulltext.ScienceDirect.java
@Override public Optional<URL> findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional<URL> pdfLink = Optional.empty(); // Try unique DOI first Optional<DOI> doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); if (doi.isPresent()) { // Available in catalog? try {//from w ww .jav a 2 s . com String sciLink = getUrlByDoi(doi.get().getDOI()); if (!sciLink.isEmpty()) { // Retrieve PDF link Document html = Jsoup.connect(sciLink).ignoreHttpErrors(true).get(); Element link = html.getElementById("pdfLink"); if (link != null) { LOGGER.info("Fulltext PDF found @ ScienceDirect."); pdfLink = Optional.of(new URL(link.attr("pdfurl"))); } } } catch (UnirestException e) { LOGGER.warn("ScienceDirect API request failed", e); } } return pdfLink; }
From source file:com.buildria.mocking.serializer.JacksonJsonSerializer.java
@Override public byte[] serialize(@Nonnull Object obj) throws IOException { Objects.requireNonNull(obj); ByteArrayOutputStream out = new ByteArrayOutputStream(); JsonEncoding encoding = mappingFrom(ctx.getCharset()); try (JsonGenerator g = new JsonFactory().createGenerator(out, encoding)) { ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(g, obj);//from w w w . ja va 2 s .c o m } return out.toByteArray(); }
From source file:net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter.java
@Override public String format(String text) { String result = Objects.requireNonNull(text); if (result.isEmpty()) { return result; }/* ww w .j ava2 s . c o m*/ StringBuilder sb = new StringBuilder(); // Deal with the form <sup>k</sup>and <sub>k</sub> result = result.replaceAll("<[ ]?sup>([^<]+)</sup>", "\\\\textsuperscript\\{$1\\}"); result = result.replaceAll("<[ ]?sub>([^<]+)</sub>", "\\\\textsubscript\\{$1\\}"); // TODO: maybe rewrite this based on regular expressions instead // Note that (at least) the IEEE Xplore fetcher must be fixed as it relies on the current way to // remove tags for its image alt-tag to equation converter for (int i = 0; i < result.length(); i++) { int c = result.charAt(i); if (c == '<') { i = readTag(result, i); } else { sb.append((char) c); } } result = sb.toString(); // Handle text based HTML entities Set<String> patterns = HTMLUnicodeConversionMaps.HTML_LATEX_CONVERSION_MAP.keySet(); for (String pattern : patterns) { result = result.replace(pattern, HTMLUnicodeConversionMaps.HTML_LATEX_CONVERSION_MAP.get(pattern)); } // Handle numerical HTML entities Matcher m = ESCAPED_PATTERN.matcher(result); while (m.find()) { int num = Integer.decode(m.group(1).replace("x", "#") + m.group(3)); if (HTMLUnicodeConversionMaps.NUMERICAL_LATEX_CONVERSION_MAP.containsKey(num)) { result = result.replace("&#" + m.group(1) + m.group(2) + m.group(3) + ";", HTMLUnicodeConversionMaps.NUMERICAL_LATEX_CONVERSION_MAP.get(num)); } } // Combining accents m = ESCAPED_PATTERN2.matcher(result); while (m.find()) { int num = Integer.decode(m.group(2).replace("x", "#") + m.group(4)); if (HTMLUnicodeConversionMaps.ESCAPED_ACCENTS.containsKey(num)) { if ("i".equals(m.group(1))) { result = result.replace(m.group(1) + "&#" + m.group(2) + m.group(3) + m.group(4) + ";", "{\\" + HTMLUnicodeConversionMaps.ESCAPED_ACCENTS.get(num) + "{\\i}}"); } else if ("j".equals(m.group(1))) { result = result.replace(m.group(1) + "&#" + m.group(2) + m.group(3) + m.group(4) + ";", "{\\" + HTMLUnicodeConversionMaps.ESCAPED_ACCENTS.get(num) + "{\\j}}"); } else { result = result.replace(m.group(1) + "&#" + m.group(2) + m.group(3) + m.group(4) + ";", "{\\" + HTMLUnicodeConversionMaps.ESCAPED_ACCENTS.get(num) + "{" + m.group(1) + "}}"); } } } // Find non-converted numerical characters m = ESCAPED_PATTERN3.matcher(result); while (m.find()) { int num = Integer.decode(m.group(1).replace("x", "#") + m.group(3)); LOGGER.warn("HTML escaped char not converted: " + m.group(1) + m.group(2) + m.group(3) + " = " + Integer.toString(num)); } // Remove $$ in case of two adjacent conversions result = result.replace("$$", ""); // Find non-covered special characters with alphabetic codes m = ESCAPED_PATTERN4.matcher(result); while (m.find()) { LOGGER.warn("HTML escaped char not converted: " + m.group(1)); } return result.trim(); }
From source file:com.asakusafw.testdriver.compiler.util.DeploymentUtil.java
/** * Deploys an artifact onto the directory. * @param source the source file/directory * @param destination the target directory * @param options the operation options/*from w w w . j a v a2s . c o m*/ * @throws IOException if I/O error was occurred */ public static void deployToDirectory(File source, File destination, DeployOption... options) throws IOException { Objects.requireNonNull(source); Objects.requireNonNull(destination); Objects.requireNonNull(options); deploy(source, new File(destination, source.getName()), options); }
From source file:com.javacreed.secureproperties.utils.DbHelper.java
/** * * @param dataSource// w w w . j av a 2s .c om * @throws NullPointerException */ public DbHelper(final BasicDataSource dataSource) throws NullPointerException { this.dataSource = Objects.requireNonNull(dataSource); }
From source file:eu.itesla_project.modules.rules.CheckSecurityTool.java
private static void writeCsv( Map<String, Map<SecurityIndexType, SecurityRuleCheckStatus>> checkStatusPerContingency, Set<SecurityIndexType> securityIndexTypes, Path outputCsvFile) throws IOException { Objects.requireNonNull(outputCsvFile); try (BufferedWriter writer = Files.newBufferedWriter(outputCsvFile, StandardCharsets.UTF_8)) { writer.write("Contingency"); for (SecurityIndexType securityIndexType : securityIndexTypes) { writer.write(CSV_SEPARATOR); writer.write(securityIndexType.toString()); }// ww w . j a v a2 s. c o m writer.newLine(); for (Map.Entry<String, Map<SecurityIndexType, SecurityRuleCheckStatus>> entry : checkStatusPerContingency .entrySet()) { String contingencyId = entry.getKey(); Map<SecurityIndexType, SecurityRuleCheckStatus> checkStatus = entry.getValue(); writer.write(contingencyId); for (SecurityIndexType securityIndexType : securityIndexTypes) { writer.write(CSV_SEPARATOR); writer.write(checkStatus.get(securityIndexType).name()); } writer.newLine(); } } }
From source file:com.github.horrorho.inflatabledonkey.requests.CkAppInitBackupRequestFactory.java
CkAppInitBackupRequestFactory(String url, Map<Headers, Header> headers) { this.url = Objects.requireNonNull(url); this.headers = new HashMap<>(headers); }