本文整理了Java中com.apollographql.apollo.api.internal.Optional.fromNullable()
方法的一些代码示例,展示了Optional.fromNullable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.fromNullable()
方法的具体详情如下:
包路径:com.apollographql.apollo.api.internal.Optional
类名称:Optional
方法名:fromNullable
[英]If nullableReference is non-null, returns an Optional instance containing that reference; otherwise returns Optional#absent.
Comparison to java.util.Optional: this method is equivalent to Java 8's Optional.ofNullable.
[中]如果nullableReference为非null,则返回包含该引用的可选实例;否则返回可选#缺席。
与java的比较。util。可选:此方法相当于Java8的可选方法。完全可以。
代码示例来源:origin: apollographql/apollo-android
public InterceptorResponse(okhttp3.Response httpResponse, Response parsedResponse,
Collection<Record> cacheRecords) {
this.httpResponse = Optional.fromNullable(httpResponse);
this.parsedResponse = Optional.fromNullable(parsedResponse);
this.cacheRecords = Optional.fromNullable(cacheRecords);
}
}
代码示例来源:origin: apollographql/apollo-android
public Builder optimisticUpdates(Operation.Data optimisticUpdates) {
this.optimisticUpdates = Optional.fromNullable(optimisticUpdates);
return this;
}
代码示例来源:origin: apollographql/apollo-android
/**
* The {@link Logger} to use for logging purposes.
*
* @return The {@link Builder} object to be used for chaining method calls
*/
public Builder logger(@Nullable Logger logger) {
this.logger = Optional.fromNullable(logger);
return this;
}
代码示例来源:origin: apollographql/apollo-android
@NotNull @Override public Optional<Record> apply(@NotNull NormalizedCache cache) {
return Optional.fromNullable(cache.loadRecord(key, cacheHeaders));
}
});
代码示例来源:origin: apollographql/apollo-android
/**
* Set the configuration to be used for normalized cache.
*
* @param normalizedCacheFactory the {@link NormalizedCacheFactory} used to construct a {@link NormalizedCache}.
* @param keyResolver the {@link CacheKeyResolver} to use to normalize records
* @return The {@link Builder} object to be used for chaining method calls
*/
public Builder normalizedCache(@NotNull NormalizedCacheFactory normalizedCacheFactory,
@NotNull CacheKeyResolver keyResolver) {
cacheFactory = Optional.fromNullable(checkNotNull(normalizedCacheFactory, "normalizedCacheFactory == null"));
cacheKeyResolver = Optional.fromNullable(checkNotNull(keyResolver, "cacheKeyResolver == null"));
return this;
}
代码示例来源:origin: apollographql/apollo-android
synchronized Optional<ApolloCall.Callback<T>> responseCallback() {
switch (state.get()) {
case ACTIVE:
case CANCELED:
return Optional.fromNullable(originalCallback.get());
case IDLE:
case TERMINATED:
throw new IllegalStateException(
CallState.IllegalStateMessage.forCurrentState(state.get()).expected(ACTIVE, CANCELED));
default:
throw new IllegalStateException("Unknown state");
}
}
代码示例来源:origin: apollographql/apollo-android
synchronized Optional<Callback<T>> responseCallback() {
switch (state.get()) {
case ACTIVE:
case CANCELED:
return Optional.fromNullable(originalCallback.get());
case IDLE:
case TERMINATED:
throw new IllegalStateException(
CallState.IllegalStateMessage.forCurrentState(state.get()).expected(ACTIVE, CANCELED));
default:
throw new IllegalStateException("Unknown state");
}
}
代码示例来源:origin: apollographql/apollo-android
synchronized Optional<Callback<T>> terminate() {
switch (state.get()) {
case ACTIVE:
tracker.unregisterCall(this);
state.set(TERMINATED);
return Optional.fromNullable(originalCallback.getAndSet(null));
case CANCELED:
return Optional.fromNullable(originalCallback.getAndSet(null));
case IDLE:
case TERMINATED:
throw new IllegalStateException(
CallState.IllegalStateMessage.forCurrentState(state.get()).expected(ACTIVE, CANCELED));
default:
throw new IllegalStateException("Unknown state");
}
}
代码示例来源:origin: apollographql/apollo-android
synchronized Optional<ApolloPrefetch.Callback> terminate() {
switch (state.get()) {
case ACTIVE:
tracker.unregisterPrefetchCall(this);
state.set(TERMINATED);
return Optional.fromNullable(originalCallback.getAndSet(null));
case CANCELED:
return Optional.fromNullable(originalCallback.getAndSet(null));
case IDLE:
case TERMINATED:
throw new IllegalStateException(
CallState.IllegalStateMessage.forCurrentState(state.get()).expected(ACTIVE, CANCELED));
default:
throw new IllegalStateException("Unknown state");
}
}
}
代码示例来源:origin: apollographql/apollo-android
synchronized Optional<ApolloCall.Callback<T>> terminate() {
switch (state.get()) {
case ACTIVE:
tracker.unregisterQueryWatcher(this);
state.set(TERMINATED);
return Optional.fromNullable(originalCallback.getAndSet(null));
case CANCELED:
return Optional.fromNullable(originalCallback.getAndSet(null));
case IDLE:
case TERMINATED:
throw new IllegalStateException(
CallState.IllegalStateMessage.forCurrentState(state.get()).expected(ACTIVE, CANCELED));
default:
throw new IllegalStateException("Unknown state");
}
}
代码示例来源:origin: apollographql/apollo-android
public ApolloHttpCache(@NotNull final HttpCacheStore cacheStore, @Nullable final Logger logger) {
this.cacheStore = checkNotNull(cacheStore, "cacheStore == null");
this.logger = new ApolloLogger(Optional.fromNullable(logger));
}
代码示例来源:origin: apollographql/apollo-android
public ApolloServerInterceptor(@NotNull HttpUrl serverUrl, @NotNull Call.Factory httpCallFactory,
@Nullable HttpCachePolicy.Policy cachePolicy, boolean prefetch,
@NotNull ScalarTypeAdapters scalarTypeAdapters, @NotNull ApolloLogger logger) {
this.serverUrl = checkNotNull(serverUrl, "serverUrl == null");
this.httpCallFactory = checkNotNull(httpCallFactory, "httpCallFactory == null");
this.cachePolicy = Optional.fromNullable(cachePolicy);
this.prefetch = prefetch;
this.scalarTypeAdapters = checkNotNull(scalarTypeAdapters, "scalarTypeAdapters == null");
this.logger = checkNotNull(logger, "logger == null");
}
代码示例来源:origin: apollographql/apollo-android
private void log(int priority, @NotNull String message, @Nullable Throwable t, Object... args) {
if (logger.isPresent()) {
logger.get().log(priority, message, Optional.fromNullable(t), args);
}
}
}
代码示例来源:origin: apollographql/apollo-android
@SuppressWarnings("unchecked") private void resolveObjectFields(FieldDescriptor fieldDescriptor,
Map<String, Object> rawFieldValues, ResolveDelegate<Map<String, Object>> delegate) {
delegate.willResolveObject(fieldDescriptor.field, Optional.fromNullable(rawFieldValues));
if (fieldDescriptor.value == null) {
delegate.didResolveNull();
} else {
resolveFields(operationVariables, delegate, (Map<String, FieldDescriptor>) fieldDescriptor.value);
}
delegate.didResolveObject(fieldDescriptor.field, Optional.fromNullable(rawFieldValues));
}
代码示例来源:origin: apollographql/apollo-android
@Override
public <D extends Mutation.Data, T, V extends Mutation.Variables> ApolloMutationCall<T> mutate(
@NotNull Mutation<D, T, V> mutation, @NotNull D withOptimisticUpdates) {
checkNotNull(withOptimisticUpdates, "withOptimisticUpdate == null");
return newCall(mutation).toBuilder().responseFetcher(ApolloResponseFetchers.NETWORK_ONLY)
.optimisticUpdates(Optional.<Operation.Data>fromNullable(withOptimisticUpdates)).build();
}
代码示例来源:origin: apollographql/apollo-android
@Override public ApolloQueryWatcher<T> enqueueAndWatch(@Nullable final ApolloCall.Callback<T> callback) {
try {
activate(Optional.fromNullable(callback));
} catch (ApolloCanceledException e) {
if (callback != null) {
callback.onCanceledError(e);
} else {
logger.e(e, "Operation: %s was canceled", operation().name().name());
}
return this;
}
activeCall.enqueue(callbackProxy());
return this;
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testFromNullable() {
Optional<String> optionalName = Optional.fromNullable("bob");
assertEquals("bob", optionalName.get());
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testFromNullableNull() {
// not promised by spec, but easier to test
assertSame(Optional.absent(), Optional.fromNullable(null));
}
代码示例来源:origin: apollographql/apollo-android
@Override public void enqueue(@Nullable final Callback responseCallback) {
try {
activate(Optional.fromNullable(responseCallback));
} catch (ApolloCanceledException e) {
if (responseCallback != null) {
responseCallback.onFailure(e);
} else {
logger.e(e, "Operation: %s was canceled", operation().name().name());
}
return;
}
ApolloInterceptor.InterceptorRequest request = ApolloInterceptor.InterceptorRequest.builder(operation).build();
interceptorChain.proceedAsync(request, dispatcher, interceptorCallbackProxy());
}
代码示例来源:origin: apollographql/apollo-android
@Override public void enqueue(@Nullable final Callback<T> responseCallback) {
try {
activate(Optional.fromNullable(responseCallback));
} catch (ApolloCanceledException e) {
if (responseCallback != null) {
responseCallback.onCanceledError(e);
} else {
logger.e(e, "Operation: %s was canceled", operation().name().name());
}
return;
}
ApolloInterceptor.InterceptorRequest request = ApolloInterceptor.InterceptorRequest.builder(operation)
.cacheHeaders(cacheHeaders)
.fetchFromCache(false)
.optimisticUpdates(optimisticUpdates)
.build();
interceptorChain.proceedAsync(request, dispatcher, interceptorCallbackProxy());
}
内容来源于网络,如有侵权,请联系作者删除!