本文整理了Java中com.apollographql.apollo.api.internal.Optional.isPresent()
方法的一些代码示例,展示了Optional.isPresent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.isPresent()
方法的具体详情如下:
包路径:com.apollographql.apollo.api.internal.Optional
类名称:Optional
方法名:isPresent
[英]Returns true if this holder contains a (non-null) instance.
Comparison to java.util.Optional: no differences.
[中]如果此持有者包含(非空)实例,则返回true。
与java的比较。util。可选:无差异。
代码示例来源:origin: apollographql/apollo-android
@Override public Map<Class, Map<String, Record>> dump() {
Map<String, Record> records = new LinkedHashMap<>();
for (Map.Entry<String, RecordJournal> entry : lruCache.asMap().entrySet()) {
records.put(entry.getKey(), entry.getValue().snapshot);
}
Map<Class, Map<String, Record>> dump = new LinkedHashMap<>();
dump.put(this.getClass(), Collections.unmodifiableMap(records));
if (nextCache().isPresent()) {
dump.putAll(nextCache().get().dump());
}
return dump;
}
代码示例来源: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
@Override public Map<Class, Map<String, Record>> dump() {
Map<Class, Map<String, Record>> dump = new LinkedHashMap<>();
dump.put(this.getClass(), Collections.unmodifiableMap(new LinkedHashMap<>(lruCache.asMap())));
if (nextCache().isPresent()) {
dump.putAll(nextCache().get().dump());
}
return dump;
}
}
代码示例来源:origin: apollographql/apollo-android
public final NormalizedCacheFactory<T> chain(@NotNull NormalizedCacheFactory factory) {
checkNotNull(factory, "factory == null");
NormalizedCacheFactory leafFactory = this;
while (leafFactory.nextFactory.isPresent()) {
leafFactory = (NormalizedCacheFactory) leafFactory.nextFactory.get();
}
leafFactory.nextFactory = Optional.of(factory);
return this;
}
}
代码示例来源:origin: apollographql/apollo-android
public final NormalizedCache chain(@NotNull NormalizedCache cache) {
checkNotNull(cache, "cache == null");
NormalizedCache leafCache = this;
while (leafCache.nextCache.isPresent()) {
leafCache = leafCache.nextCache.get();
}
leafCache.nextCache = Optional.of(cache);
return this;
}
代码示例来源:origin: apollographql/apollo-android
@Override public synchronized void cancel() {
switch (state.get()) {
case ACTIVE:
state.set(CANCELED);
try {
interceptorChain.dispose();
if (queryReFetcher.isPresent()) {
queryReFetcher.get().cancel();
}
} finally {
tracker.unregisterCall(this);
originalCallback.set(null);
}
break;
case IDLE:
state.set(CANCELED);
break;
case CANCELED:
case TERMINATED:
// These are not illegal states, but cancelling does nothing
break;
default:
throw new IllegalStateException("Unknown state");
}
}
代码示例来源:origin: apollographql/apollo-android
@Override public void onResponse(@NotNull InterceptorResponse response) {
if (disposed) return;
Optional<InterceptorRequest> retryRequest = handleProtocolNegotiation(request, response);
if (retryRequest.isPresent()) {
chain.proceedAsync(retryRequest.get(), dispatcher, callBack);
} else {
callBack.onResponse(response);
callBack.onCompleted();
}
}
代码示例来源:origin: apollographql/apollo-android
@Override public void run() {
try {
if (request.optimisticUpdates.isPresent()) {
Operation.Data optimisticUpdates = request.optimisticUpdates.get();
apolloStore.writeOptimisticUpdatesAndPublish(request.operation, optimisticUpdates, request.uniqueId)
.execute();
}
} catch (Exception e) {
logger.e(e, "failed to write operation optimistic updates, for: %s", request.operation);
}
}
});
代码示例来源:origin: apollographql/apollo-android
@Test
public void testIsPresentYes() {
assertTrue(Optional.of("training").isPresent());
}
代码示例来源:origin: apollographql/apollo-android
@Override public void onCompleted() {
Optional<Callback<T>> callback = terminate();
if (queryReFetcher.isPresent()) {
queryReFetcher.get().refetch();
}
if (!callback.isPresent()) {
logger.d("onCompleted for operation: %s. No callback present.", operation().name().name());
return;
}
callback.get().onStatusEvent(StatusEvent.COMPLETED);
}
代码示例来源:origin: apollographql/apollo-android
public final NormalizedCache createChain(final RecordFieldJsonAdapter recordFieldAdapter) {
if (nextFactory.isPresent()) {
return create(recordFieldAdapter)
.chain(nextFactory.map(new Function<NormalizedCacheFactory, NormalizedCache>() {
@NotNull @Override public NormalizedCache apply(@NotNull NormalizedCacheFactory factory) {
return factory.createChain(recordFieldAdapter);
}
}).get());
} else {
return create(recordFieldAdapter);
}
}
代码示例来源:origin: apollographql/apollo-android
@Override public void willResolveObject(ResponseField field, Optional<R> objectSource) {
pathStack.push(path);
CacheKey cacheKey = objectSource.isPresent() ? resolveCacheKey(field, objectSource.get()) : CacheKey.NO_KEY;
String cacheKeyValue = cacheKey.key();
if (cacheKey.equals(CacheKey.NO_KEY)) {
cacheKeyValue = pathToString();
} else {
path = new ArrayList<>();
path.add(cacheKeyValue);
}
recordStack.push(currentRecordBuilder.build());
currentRecordBuilder = Record.builder(cacheKeyValue);
}
代码示例来源:origin: apollographql/apollo-android
@Override public void onResponse(@NotNull final ApolloInterceptor.InterceptorResponse response) {
Optional<Callback<T>> callback = responseCallback();
if (!callback.isPresent()) {
logger.d("onResponse for operation: %s. No callback present.", operation().name().name());
return;
}
//noinspection unchecked
callback.get().onResponse(response.parsedResponse.get());
}
代码示例来源:origin: apollographql/apollo-android
@Override public void didResolveObject(ResponseField field, Optional<R> objectSource) {
path = pathStack.pop();
if (objectSource.isPresent()) {
Record completedRecord = currentRecordBuilder.build();
valueStack.push(new CacheReference(completedRecord.key()));
dependentKeys.add(completedRecord.key());
recordSet.merge(completedRecord);
}
currentRecordBuilder = recordStack.pop().toBuilder();
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testAbsent() {
Optional<String> optionalName = Optional.absent();
assertFalse(optionalName.isPresent());
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testIsPresentNo() {
assertFalse(Optional.absent().isPresent());
}
代码示例来源:origin: apollographql/apollo-android
@Override public void onResponse(@NotNull ApolloInterceptor.InterceptorResponse response) {
Response httpResponse = response.httpResponse.get();
try {
Optional<Callback> callback = terminate();
if (!callback.isPresent()) {
logger.d("onResponse for prefetch operation: %s. No callback present.", operation().name().name());
return;
}
if (httpResponse.isSuccessful()) {
callback.get().onSuccess();
} else {
callback.get().onHttpError(new ApolloHttpException(httpResponse));
}
} finally {
httpResponse.close();
}
}
代码示例来源:origin: apollographql/apollo-android
LruNormalizedCache(EvictionPolicy evictionPolicy) {
final CacheBuilder<Object, Object> lruCacheBuilder = CacheBuilder.newBuilder();
if (evictionPolicy.maxSizeBytes().isPresent()) {
lruCacheBuilder.maximumWeight(evictionPolicy.maxSizeBytes().get())
.weigher(new Weigher<String, Record>() {
@Override public int weigh(String key, Record value) {
return key.getBytes(Charset.defaultCharset()).length + value.sizeEstimateBytes();
}
});
}
if (evictionPolicy.maxEntries().isPresent()) {
lruCacheBuilder.maximumSize(evictionPolicy.maxEntries().get());
}
if (evictionPolicy.expireAfterAccess().isPresent()) {
lruCacheBuilder.expireAfterAccess(evictionPolicy.expireAfterAccess().get(),
evictionPolicy.expireAfterAccessTimeUnit().get());
}
if (evictionPolicy.expireAfterWrite().isPresent()) {
lruCacheBuilder.expireAfterWrite(evictionPolicy.expireAfterWrite().get(),
evictionPolicy.expireAfterWriteTimeUnit().get());
}
lruCache = lruCacheBuilder.build();
}
代码示例来源:origin: apollographql/apollo-android
@Override public void onFailure(@NotNull ApolloException e) {
Optional<Callback> callback = terminate();
if (!callback.isPresent()) {
logger.e(e, "onFailure for prefetch operation: %s. No callback present.", operation().name().name());
return;
}
if (e instanceof ApolloHttpException) {
callback.get().onHttpError((ApolloHttpException) e);
} else if (e instanceof ApolloNetworkException) {
callback.get().onNetworkError((ApolloNetworkException) e);
} else {
callback.get().onFailure(e);
}
}
代码示例来源:origin: apollographql/apollo-android
@Override public void onFailure(@NotNull ApolloException e) {
Optional<Callback<T>> callback = terminate();
if (!callback.isPresent()) {
logger.d(e, "onFailure for operation: %s. No callback present.", operation().name().name());
return;
}
if (e instanceof ApolloHttpException) {
callback.get().onHttpError((ApolloHttpException) e);
} else if (e instanceof ApolloParseException) {
callback.get().onParseError((ApolloParseException) e);
} else if (e instanceof ApolloNetworkException) {
callback.get().onNetworkError((ApolloNetworkException) e);
} else {
callback.get().onFailure(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!