本文整理了Java中com.apollographql.apollo.api.internal.Optional.orNull()
方法的一些代码示例,展示了Optional.orNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.orNull()
方法的具体详情如下:
包路径:com.apollographql.apollo.api.internal.Optional
类名称:Optional
方法名:orNull
[英]Returns the contained instance if it is present; null otherwise. If the instance is known to be present, use #get() instead.
Comparison to java.util.Optional: this method is equivalent to Java 8's Optional.orElse(null).
[中]返回包含的实例(如果存在);否则为空。如果已知实例存在,请使用#get()代替。
与java的比较。util。可选:此方法相当于Java8的可选方法。orElse(空)。
代码示例来源:origin: apollographql/apollo-android
private synchronized void activate(Optional<ApolloCall.Callback<T>> callback) throws ApolloCanceledException {
switch (state.get()) {
case IDLE:
originalCallback.set(callback.orNull());
tracker.registerQueryWatcher(this);
break;
case CANCELED:
throw new ApolloCanceledException("Call is cancelled.");
case TERMINATED:
case ACTIVE:
throw new IllegalStateException("Already Executed");
default:
throw new IllegalStateException("Unknown state");
}
state.set(ACTIVE);
}
代码示例来源:origin: apollographql/apollo-android
private synchronized void activate(Optional<ApolloPrefetch.Callback> callback) throws ApolloCanceledException {
switch (state.get()) {
case IDLE:
originalCallback.set(callback.orNull());
tracker.registerPrefetchCall(this);
break;
case CANCELED:
throw new ApolloCanceledException("Call is cancelled.");
case TERMINATED:
case ACTIVE:
throw new IllegalStateException("Already Executed");
default:
throw new IllegalStateException("Unknown state");
}
state.set(ACTIVE);
}
代码示例来源:origin: apollographql/apollo-android
@SuppressWarnings("ResultOfMethodCallIgnored")
private synchronized void activate(Optional<Callback<T>> callback) {
switch (state.get()) {
case IDLE:
originalCallback.set(callback.orNull());
tracker.registerCall(this);
callback.apply(new Action<Callback<T>>() {
@Override public void apply(@NotNull Callback<T> callback) {
callback.onStatusEvent(StatusEvent.SCHEDULED);
}
});
break;
case CANCELED:
throw new ApolloCanceledException("Call is cancelled.");
case TERMINATED:
case ACTIVE:
throw new IllegalStateException("Already Executed");
default:
throw new IllegalStateException("Unknown state");
}
state.set(ACTIVE);
}
代码示例来源:origin: apollographql/apollo-android
public Builder toBuilder() {
return new Builder(operation)
.cacheHeaders(cacheHeaders)
.fetchFromCache(fetchFromCache)
.optimisticUpdates(optimisticUpdates.orNull())
.sendQueryDocument(sendQueryDocument);
}
代码示例来源:origin: apollographql/apollo-android
@Nullable @Override public Record loadRecord(@NotNull final String key, @NotNull final CacheHeaders cacheHeaders) {
checkNotNull(key, "key == null");
checkNotNull(cacheHeaders, "cacheHeaders == null");
try {
final Optional<Record> nonOptimisticRecord = nextCache()
.flatMap(new Function<NormalizedCache, Optional<Record>>() {
@NotNull @Override public Optional<Record> apply(@NotNull NormalizedCache cache) {
return Optional.fromNullable(cache.loadRecord(key, cacheHeaders));
}
});
final RecordJournal journal = lruCache.getIfPresent(key);
if (journal != null) {
return nonOptimisticRecord.map(new Function<Record, Record>() {
@NotNull @Override public Record apply(@NotNull Record record) {
Record result = record.clone();
result.mergeWith(journal.snapshot);
return result;
}
}).or(journal.snapshot.clone());
} else {
return nonOptimisticRecord.orNull();
}
} catch (Exception ignore) {
return null;
}
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testOrNullPresent() {
assertEquals("a", Optional.of("a").orNull());
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testOrNullAbsent() {
assertNull(Optional.absent().orNull());
}
代码示例来源:origin: com.amazonaws/aws-android-sdk-appsync-runtime
private synchronized void activate(Optional<GraphQLCall.Callback<T>> callback) throws ApolloCanceledException {
switch (state.get()) {
case IDLE:
originalCallback.set(callback.orNull());
tracker.registerQueryWatcher(this);
break;
case CANCELED:
throw new ApolloCanceledException("Call is cancelled.");
case TERMINATED:
case ACTIVE:
throw new IllegalStateException("Already Executed");
default:
throw new IllegalStateException("Unknown state");
}
state.set(ACTIVE);
}
代码示例来源:origin: com.amazonaws/aws-android-sdk-appsync-runtime
private synchronized void activate(Optional<Callback> callback) throws ApolloCanceledException {
switch (state.get()) {
case IDLE:
originalCallback.set(callback.orNull());
tracker.registerPrefetchCall(this);
break;
case CANCELED:
throw new ApolloCanceledException("Call is cancelled.");
case TERMINATED:
case ACTIVE:
throw new IllegalStateException("Already Executed");
default:
throw new IllegalStateException("Unknown state");
}
state.set(ACTIVE);
}
代码示例来源:origin: awslabs/aws-mobile-appsync-sdk-android
private synchronized void activate(Optional<Callback> callback) throws ApolloCanceledException {
switch (state.get()) {
case IDLE:
originalCallback.set(callback.orNull());
tracker.registerPrefetchCall(this);
break;
case CANCELED:
throw new ApolloCanceledException("Call is cancelled.");
case TERMINATED:
case ACTIVE:
throw new IllegalStateException("Already Executed");
default:
throw new IllegalStateException("Unknown state");
}
state.set(ACTIVE);
}
代码示例来源:origin: awslabs/aws-mobile-appsync-sdk-android
private synchronized void activate(Optional<GraphQLCall.Callback<T>> callback) throws ApolloCanceledException {
switch (state.get()) {
case IDLE:
originalCallback.set(callback.orNull());
tracker.registerQueryWatcher(this);
break;
case CANCELED:
throw new ApolloCanceledException("Call is cancelled.");
case TERMINATED:
case ACTIVE:
throw new IllegalStateException("Already Executed");
default:
throw new IllegalStateException("Unknown state");
}
state.set(ACTIVE);
}
代码示例来源:origin: com.amazonaws/aws-android-sdk-appsync-runtime
private synchronized void activate(Optional<Callback<T>> callback) throws ApolloCanceledException {
switch (state.get()) {
case IDLE:
originalCallback.set(callback.orNull());
tracker.registerCall(this);
callback.apply(new Action<Callback<T>>() {
@Override public void apply(@Nonnull Callback<T> callback) {
callback.onStatusEvent(StatusEvent.SCHEDULED);
}
});
break;
case CANCELED:
throw new ApolloCanceledException("Call is cancelled.");
case TERMINATED:
case ACTIVE:
throw new IllegalStateException("Already Executed");
default:
throw new IllegalStateException("Unknown state");
}
state.set(ACTIVE);
}
代码示例来源:origin: awslabs/aws-mobile-appsync-sdk-android
private synchronized void activate(Optional<Callback<T>> callback) throws ApolloCanceledException {
switch (state.get()) {
case IDLE:
originalCallback.set(callback.orNull());
tracker.registerCall(this);
callback.apply(new Action<Callback<T>>() {
@Override public void apply(@Nonnull Callback<T> callback) {
callback.onStatusEvent(StatusEvent.SCHEDULED);
}
});
break;
case CANCELED:
throw new ApolloCanceledException("Call is cancelled.");
case TERMINATED:
case ACTIVE:
throw new IllegalStateException("Already Executed");
default:
throw new IllegalStateException("Unknown state");
}
state.set(ACTIVE);
}
代码示例来源:origin: awslabs/aws-mobile-appsync-sdk-android
@Nullable public Record loadRecord(@Nonnull final String key, @Nonnull final CacheHeaders cacheHeaders) {
return selectRecordForKey(key)
.apply(new Action<Record>() {
@Override
public void apply(@Nonnull Record record) {
if (cacheHeaders.hasHeader(EVICT_AFTER_READ)) {
deleteRecord(key);
}
}
})
.or(nextCache().flatMap(new Function<NormalizedCache, Optional<Record>>() {
@Nonnull @Override
public Optional<Record> apply(@Nonnull NormalizedCache cache) {
return Optional.fromNullable(cache.loadRecord(key, cacheHeaders));
}
}))
.orNull();
}
代码示例来源:origin: com.amazonaws/aws-android-sdk-appsync-runtime
public Builder toBuilder() {
return new Builder(operation)
.cacheHeaders(cacheHeaders)
.fetchFromCache(fetchFromCache)
.optimisticUpdates(optimisticUpdates.orNull());
}
代码示例来源:origin: awslabs/aws-mobile-appsync-sdk-android
public Builder toBuilder() {
return new Builder(operation)
.cacheHeaders(cacheHeaders)
.fetchFromCache(fetchFromCache)
.optimisticUpdates(optimisticUpdates.orNull());
}
代码示例来源:origin: com.amazonaws/aws-android-sdk-appsync-runtime
@Nullable @Override public Record loadRecord(@Nonnull final String key, @Nonnull final CacheHeaders cacheHeaders) {
checkNotNull(key, "key == null");
checkNotNull(cacheHeaders, "cacheHeaders == null");
try {
final Optional<Record> nonOptimisticRecord = nextCache()
.flatMap(new Function<NormalizedCache, Optional<Record>>() {
@Nonnull @Override public Optional<Record> apply(@Nonnull NormalizedCache cache) {
return Optional.fromNullable(cache.loadRecord(key, cacheHeaders));
}
});
final RecordJournal journal = lruCache.getIfPresent(key);
if (journal != null) {
return nonOptimisticRecord.map(new Function<Record, Record>() {
@Nonnull @Override public Record apply(@Nonnull Record record) {
Record result = record.clone();
result.mergeWith(journal.snapshot);
return result;
}
}).or(journal.snapshot.clone());
} else {
return nonOptimisticRecord.orNull();
}
} catch (Exception ignore) {
return null;
}
}
代码示例来源:origin: awslabs/aws-mobile-appsync-sdk-android
@Nullable @Override public Record loadRecord(@Nonnull final String key, @Nonnull final CacheHeaders cacheHeaders) {
checkNotNull(key, "key == null");
checkNotNull(cacheHeaders, "cacheHeaders == null");
try {
final Optional<Record> nonOptimisticRecord = nextCache()
.flatMap(new Function<NormalizedCache, Optional<Record>>() {
@Nonnull @Override public Optional<Record> apply(@Nonnull NormalizedCache cache) {
return Optional.fromNullable(cache.loadRecord(key, cacheHeaders));
}
});
final RecordJournal journal = lruCache.getIfPresent(key);
if (journal != null) {
return nonOptimisticRecord.map(new Function<Record, Record>() {
@Nonnull @Override public Record apply(@Nonnull Record record) {
Record result = record.clone();
result.mergeWith(journal.snapshot);
return result;
}
}).or(journal.snapshot.clone());
} else {
return nonOptimisticRecord.orNull();
}
} catch (Exception ignore) {
return null;
}
}
内容来源于网络,如有侵权,请联系作者删除!