Example usage for java.util Objects requireNonNull

List of usage examples for java.util Objects requireNonNull

Introduction

In this page you can find the example usage for java.util Objects requireNonNull.

Prototype

public static <T> T requireNonNull(T obj) 

Source Link

Document

Checks that the specified object reference is not null .

Usage

From source file:net.sf.jabref.logic.fulltext.SpringerLink.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  w w.j a v  a 2s  .  c  o  m*/
            HttpResponse<JsonNode> jsonResponse = Unirest.get(API_URL).queryString("api_key", API_KEY)
                    .queryString("q", String.format("doi:%s", doi.get().getDOI())).asJson();

            JSONObject json = jsonResponse.getBody().getObject();
            int results = json.getJSONArray("result").getJSONObject(0).getInt("total");

            if (results > 0) {
                LOGGER.info("Fulltext PDF found @ Springer.");
                pdfLink = Optional.of(new URL("http", CONTENT_HOST,
                        String.format("/content/pdf/%s.pdf", doi.get().getDOI())));
            }
        } catch (UnirestException e) {
            LOGGER.warn("SpringerLink API request failed", e);
        }
    }
    return pdfLink;
}

From source file:com.hurence.logisland.util.kura.Metrics.java

/**
 * Convert plain key value map into a Kura metric structure <br>
 * Only the supported Kura values types must be used (String, boolean, int,
 * long, float, double, byte[])//  w w w .  j a  v  a 2  s  . c om
 *
 * @param builder
 *            the builder to append the metrics to
 * @param metrics
 *            the metrics map
 * @throws IllegalArgumentException
 *             in case of an unsupported value type
 */
public static void buildMetrics(final KuraPayloadProto.KuraPayload.Builder builder,
        final Map<String, ?> metrics) {
    Objects.requireNonNull(metrics);

    for (final Map.Entry<String, ?> metric : metrics.entrySet()) {
        addMetric(builder, metric.getKey(), metric.getValue());
    }
}

From source file:net.sf.jabref.logic.fetcher.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 = DOI.build(entry.getField("doi"));

    if (doi.isPresent()) {
        // Available in catalog?
        try {/*from  w w  w  .j a  v a  2s.  c  o m*/
            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:org.eclipse.hono.service.tenant.TenantHttpEndpoint.java

/**
 * Creates an endpoint for a Vertx instance.
 *
 * @param vertx The Vertx instance to use.
 * @throws NullPointerException if vertx is {@code null};
 *//*from   ww w  .j  a  v a 2  s .c  o m*/
@Autowired
public TenantHttpEndpoint(final Vertx vertx) {
    super(Objects.requireNonNull(vertx));
}

From source file:org.eclipse.hono.messaging.SenderFactoryImpl.java

/**
 * {@inheritDoc}//from  w ww.  ja  v a 2  s . c  o m
 */
@Override
public Future<ProtonSender> createSender(final ProtonConnection connection, final ResourceIdentifier address,
        final ProtonQoS qos, final Handler<ProtonSender> sendQueueDrainHandler, final Handler<Void> closeHook) {

    Objects.requireNonNull(connection);
    Objects.requireNonNull(address);
    Objects.requireNonNull(qos);

    if (connection.isDisconnected()) {
        return Future.failedFuture("connection is disconnected");
    } else {
        return newSession(connection, address).compose(session -> {
            return newSender(connection, session, address, qos, sendQueueDrainHandler, hook -> {
                closeHook.handle(null);
            });
        });
    }
}

From source file:com.github.horrorho.inflatabledonkey.responsehandler.JsonResponseHandler.java

JsonResponseHandler(ObjectMapper objectMapper, Class<T> clazz) {
    this.objectMapper = Objects.requireNonNull(objectMapper);
    this.clazz = Objects.requireNonNull(clazz);
}

From source file:net.pkhsolutions.pecsapp.model.PictureModel.java

public PictureModel(@NotNull PageModel pageModel, @NotNull PictureService pictureService) {
    this.pageModel = Objects.requireNonNull(pageModel);
    this.pictureService = Objects.requireNonNull(pictureService);
    // PictureModel always has same scope as PageModel, no need to remove the listener
    this.pageModel.getLayout().addValueChangeListener(event -> updateProperties());
    this.title.addValueChangeListener(this::titleChanged);
    this.descriptor.addValueChangeListener(this::descriptorChanged);
}

From source file:com.ait.tooling.server.core.security.SimpleSHA512HashProvider.java

@Override
public String sha512(final String text, final String salt) {
    return m_hasher.sha512(Objects.requireNonNull(text), Objects.requireNonNull(salt));
}

From source file:org.n52.iceland.statistics.api.utils.KibanaImporter.java

public void importJson(String jsonString) throws JsonParseException, JsonMappingException, IOException {
    Objects.requireNonNull(jsonString);

    // delete .kibana index
    try {/*from   ww w .j ava2 s  .c o  m*/
        client.admin().indices().prepareDelete(kibanaIndexName).get();
    } catch (ElasticsearchException ex) {
        logger.debug("Tried to delete kibana index " + kibanaIndexName + " but it is not exists", ex);
    }

    ObjectMapper mapper = new ObjectMapper();
    KibanaConfigHolderDto holder = mapper.readValue(jsonString, KibanaConfigHolderDto.class);

    for (KibanaConfigEntryDto dto : holder.getEntries()) {
        dto = processDto(dto);
        logger.debug("Importing {}", dto);
        client.prepareIndex(kibanaIndexName, dto.getType(), dto.getId()).setSource(dto.getSource()).get();
    }
}

From source file:cn.edu.zjnu.acm.judge.service.LoginlogService.java

@Transactional
public void save(LoginLog loginlog) {
    Objects.requireNonNull(loginlog);
    lock.lock();//  w w  w  . ja  v  a 2s.c  o m
    try {
        list.add(loginlog);
        condition.signal();
    } finally {
        lock.unlock();
    }
}