當前位置: 首頁>>代碼示例>>Java>>正文


Java OptionalLong.isPresent方法代碼示例

本文整理匯總了Java中java.util.OptionalLong.isPresent方法的典型用法代碼示例。如果您正苦於以下問題:Java OptionalLong.isPresent方法的具體用法?Java OptionalLong.isPresent怎麽用?Java OptionalLong.isPresent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.OptionalLong的用法示例。


在下文中一共展示了OptionalLong.isPresent方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: send

import java.util.OptionalLong; //導入方法依賴的package包/類
public RawHttpResponse<CloseableHttpResponse> send(RawHttpRequest request) throws IOException {
    RequestBuilder builder = RequestBuilder.create(request.getMethod());
    builder.setUri(request.getUri());
    builder.setVersion(toProtocolVersion(request.getStartLine().getHttpVersion()));
    request.getHeaders().getHeaderNames().forEach((name) ->
            request.getHeaders().get(name).forEach(value ->
                    builder.addHeader(new BasicHeader(name, value))));

    request.getBody().ifPresent(b -> builder.setEntity(new InputStreamEntity(b.asStream())));

    CloseableHttpResponse response = httpClient.execute(builder.build());

    RawHttpHeaders headers = readHeaders(response);

    @Nullable LazyBodyReader body;
    if (response.getEntity() != null) {
        OptionalLong headerLength = RawHttp.parseContentLength(headers);
        @Nullable Long length = headerLength.isPresent() ? headerLength.getAsLong() : null;
        BodyType bodyType = RawHttp.getBodyType(headers, length);
        body = new LazyBodyReader(bodyType, response.getEntity().getContent(), length, false);
    } else {
        body = null;
    }

    return new RawHttpResponse<>(response, request, adaptStatus(response.getStatusLine()), headers, body);
}
 
開發者ID:renatoathaydes,項目名稱:rawhttp,代碼行數:27,代碼來源:RawHttpComponentsClient.java

示例2: createBodyReader

import java.util.OptionalLong; //導入方法依賴的package包/類
@Nullable
private BodyReader createBodyReader(InputStream inputStream, RawHttpHeaders headers, boolean hasBody) {
    @Nullable BodyReader bodyReader;

    if (hasBody) {
        @Nullable Long bodyLength = null;
        OptionalLong headerLength = parseContentLength(headers);
        if (headerLength.isPresent()) {
            bodyLength = headerLength.getAsLong();
        }
        BodyType bodyType = getBodyType(headers, bodyLength);
        bodyReader = new LazyBodyReader(bodyType, inputStream, bodyLength, options.allowNewLineWithoutReturn());
    } else {
        bodyReader = null;
    }
    return bodyReader;
}
 
開發者ID:renatoathaydes,項目名稱:rawhttp,代碼行數:18,代碼來源:RawHttp.java

示例3: invokeAll

import java.util.OptionalLong; //導入方法依賴的package包/類
@SuppressWarnings({"unchecked", "OptionalUsedAsFieldOrParameterType"})
private <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, OptionalLong timeoutNanos)
    throws InterruptedException {
  Objects.requireNonNull(tasks, "'tasks' should not be 'null'.");
  CompletableFuture[] futures = new CompletableFuture[tasks.size()];
  int index = 0;
  for (Callable<T> task : tasks) {
    futures[index++] = submit(task);
  }
  boolean completeWithTimeout = timeoutNanos.isPresent();
  try {
    if (completeWithTimeout) {
      CompletableFuture.allOf(futures)
          .get(timeoutNanos.getAsLong(), TimeUnit.NANOSECONDS);
      completeWithTimeout = false;
    } else {
      CompletableFuture.allOf(futures)
          .get();
    }
  } catch (ExecutionException | TimeoutException ignored) {
    logger.error("Got exception while waiting for completion of '{}' tasks.", tasks.size(), ignored);
  }
  if (completeWithTimeout) {
    TimeoutException timeoutException = new TimeoutException(
        "Got timeout after '" + timeoutNanos.getAsLong() + "' nanos."
    );
    for (CompletableFuture future : futures) {
      future.completeExceptionally(timeoutException);
    }
  }
  return Arrays.stream(futures)
      .map(future -> (Future<T>) future)
      .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
}
 
開發者ID:sorokinigor,項目名稱:yet-another-try,代碼行數:35,代碼來源:AbstractRetryExecutorService.java

示例4: fromRepository

import java.util.OptionalLong; //導入方法依賴的package包/類
private Single<Long> fromRepository() {
    final OptionalLong mayBeTickTime = maybeMaxTickTime();
    return mayBeTickTime.isPresent()
            ? Single.just(mayBeTickTime.getAsLong())
            : Single.error(new JFException("No tick time available!"));
}
 
開發者ID:juxeii,項目名稱:dztools,代碼行數:7,代碼來源:TickTimeFetch.java

示例5: toJdbc

import java.util.OptionalLong; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 *
 * @see jp.co.future.uroborosql.parameter.mapper.BindParameterMapper#toJdbc(java.lang.Object, java.sql.Connection, jp.co.future.uroborosql.parameter.mapper.BindParameterMapperManager)
 */
@Override
public Object toJdbc(final OptionalLong original, final Connection connection,
		final BindParameterMapperManager parameterMapperManager) {
	return original.isPresent() ? original.getAsLong() : null;
}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:11,代碼來源:OptionalLongParameterMapper.java

示例6: stream

import java.util.OptionalLong; //導入方法依賴的package包/類
/**
 * If a value is present in {@code optional}, returns a stream containing only that element,
 * otherwise returns an empty stream.
 *
 * <p><b>Java 9 users:</b> use {@code optional.stream()} instead.
 */
public static LongStream stream(OptionalLong optional) {
  return optional.isPresent() ? LongStream.of(optional.getAsLong()) : LongStream.empty();
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:10,代碼來源:Streams.java


注:本文中的java.util.OptionalLong.isPresent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。