本文整理匯總了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);
}
示例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;
}
示例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));
}
示例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!"));
}
示例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;
}
示例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();
}