本文整理了Java中com.apollographql.apollo.api.internal.Optional.get()
方法的一些代码示例,展示了Optional.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.get()
方法的具体详情如下:
包路径:com.apollographql.apollo.api.internal.Optional
类名称:Optional
方法名:get
[英]Returns the contained instance, which must be present. If the instance might be absent, use #or(Object) or #orNull instead.
Comparison to java.util.Optional: when the value is absent, this method throws IllegalStateException, whereas the Java 8 counterpart throws NoSuchElementException}.
[中]返回包含的实例,该实例必须存在。如果实例可能不存在,请使用#or(Object)或#orNull。
与java的比较。util。可选:当该值不存在时,该方法抛出IllegalStateException,而Java 8对应的方法抛出NoSuchElementException}。
代码示例来源:origin: apollographql/apollo-android
@Nullable @Override public Set<String> execute(WriteableStore cache) {
return cache.merge(records.get(), request.cacheHeaders);
}
});
代码示例来源: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
@Override public Record call() throws Exception {
return nextCache().flatMap(new Function<NormalizedCache, Optional<Record>>() {
@NotNull @Override public Optional<Record> apply(@NotNull NormalizedCache cache) {
return Optional.fromNullable(cache.loadRecord(key, cacheHeaders));
}
}).get(); // lruCache.get(key, callable) requires non-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
@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 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
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
@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 onResponse(@NotNull InterceptorResponse response) {
try {
if (disposed) return;
InterceptorResponse result = parse(request.operation, response.httpResponse.get());
callBack.onResponse(result);
callBack.onCompleted();
} catch (ApolloException e) {
onFailure(e);
}
}
代码示例来源: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
@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
@Test
public void testFromNullable() {
Optional<String> optionalName = Optional.fromNullable("bob");
assertEquals("bob", optionalName.get());
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testGetAbsent() {
Optional<String> optional = Optional.absent();
try {
optional.get();
fail();
} catch (IllegalStateException ignore) {
}
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testOf() {
assertEquals("training", Optional.of("training").get());
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testGetPresent() {
assertEquals("training", Optional.of("training").get());
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testClearSecondaryCache() {
LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION);
NormalizedCache primaryCache = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION)
.chain(secondaryCacheFactory).createChain(basicFieldAdapter);
Record record = Record.builder("key").build();
primaryCache.merge(record, CacheHeaders.NONE);
primaryCache.nextCache().get().clearAll();
assertThat(primaryCache.nextCache().get().loadRecord("key", CacheHeaders.NONE)).isNull();
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testClearPrimaryCache() {
LruNormalizedCacheFactory secondaryCacheFactory = new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION);
LruNormalizedCache primaryCache = (LruNormalizedCache) new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION)
.chain(secondaryCacheFactory).createChain(basicFieldAdapter);
Record record = Record.builder("key").build();
primaryCache.merge(record, CacheHeaders.NONE);
primaryCache.clearCurrentCache();
assertThat(primaryCache.nextCache().get()
.loadRecord("key", CacheHeaders.NONE)).isNotNull();
assertThat(primaryCache.nextCache().get()
.loadRecord("key", CacheHeaders.NONE)).isNotNull();
}
内容来源于网络,如有侵权,请联系作者删除!