当前位置: 首页>>代码示例>>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;未经允许,请勿转载。