本文整理了Java中com.apollographql.apollo.api.internal.Optional.of()
方法的一些代码示例,展示了Optional.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.of()
方法的具体详情如下:
包路径:com.apollographql.apollo.api.internal.Optional
类名称:Optional
方法名:of
[英]Returns an Optional instance containing the given non-null reference. To have null treated as #absent, use #fromNullable instead.
Comparison to java.util.Optional: no differences.
[中]返回包含给定非空引用的可选实例。要将null视为#缺席,请改用#fromNullable。
与java的比较。util。可选:无差异。
代码示例来源:origin: apollographql/apollo-android
public EvictionPolicy.Builder maxSizeBytes(long maxSizeBytes) {
this.maxSizeBytes = Optional.of(maxSizeBytes);
return this;
}
代码示例来源:origin: apollographql/apollo-android
public EvictionPolicy.Builder expireAfterAccess(long time, TimeUnit timeUnit) {
this.expireAfterAccess = Optional.of(time);
this.expireAfterAccessTimeUnit = Optional.of(timeUnit);
return this;
}
代码示例来源:origin: apollographql/apollo-android
public EvictionPolicy.Builder expireAfterWrite(long time, TimeUnit timeUnit) {
this.expireAfterWrite = Optional.of(time);
this.expireAfterWriteTimeUnit = Optional.of(timeUnit);
return this;
}
代码示例来源:origin: apollographql/apollo-android
public EvictionPolicy.Builder maxEntries(long maxEntries) {
this.maxEntries = Optional.of(maxEntries);
return this;
}
代码示例来源:origin: apollographql/apollo-android
/**
* <p>Sets up subscription transport factory to be used for subscription server communication.<p/> See also: {@link
* com.apollographql.apollo.subscription.WebSocketSubscriptionTransport}
*
* @param subscriptionTransportFactory transport layer to be used for subscriptions.
* @return The {@link Builder} object to be used for chaining method calls
*/
public Builder subscriptionTransportFactory(@NotNull SubscriptionTransport.Factory subscriptionTransportFactory) {
this.subscriptionTransportFactory = Optional.of(checkNotNull(subscriptionTransportFactory,
"subscriptionTransportFactory is null"));
return this;
}
代码示例来源:origin: apollographql/apollo-android
/**
* <p>Sets up subscription connection parameters to be sent to the server when connection is established with
* subscription server</p>
*
* @param subscriptionConnectionParams map of connection parameters to be sent
* @return The {@link Builder} object to be used for chaining method calls
*/
public Builder subscriptionConnectionParams(@NotNull Map<String, Object> subscriptionConnectionParams) {
this.subscriptionConnectionParams = Optional.of(checkNotNull(subscriptionConnectionParams,
"subscriptionConnectionParams is null"));
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
@NotNull @Override public Optional<String> apply(@NotNull Integer integer) {
return Optional.of(integer.toString());
}
}));
代码示例来源: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
@Test
public void testOrOptionalPresent() {
assertEquals(Optional.of("a"), Optional.of("a").or(Optional.of("fallback")));
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testEqualsAndHashCodePresent() {
assertEquals(Optional.of("training"), Optional.of("training"));
assertFalse(Optional.of("a").equals(Optional.of("b")));
assertFalse(Optional.of("a").equals(Optional.absent()));
assertEquals(Optional.of("training").hashCode(), Optional.of("training").hashCode());
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testFlatMapMapPresentIdentity() {
assertEquals(Optional.of("a"), Optional.of("a").flatMap(new Function<String, Optional<String>>() {
@NotNull @Override public Optional<String> apply(@NotNull String s) {
return Optional.of(s);
}
})
);
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testFlatMapPresentToString() {
assertEquals(Optional.of("42"), Optional.of(42).flatMap(new Function<Integer, Optional<String>>() {
@NotNull @Override public Optional<String> apply(@NotNull Integer integer) {
return Optional.of(integer.toString());
}
}));
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testMapPresentToString() {
assertEquals(Optional.of("42"), Optional.of(42).map(Functions.toStringFunction()));
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testOfNull() {
try {
Optional.of(null);
fail();
} catch (NullPointerException ignore) {
}
}
代码示例来源:origin: apollographql/apollo-android
@SuppressWarnings("unused") // compilation test
@Test
public void testSampleCodeFine1() {
Optional<Number> optionalInt = Optional.of((Number) 1);
Number value = optionalInt.or(0.5); // fine
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testAsSetPresent() {
Set<String> expected = Collections.singleton("a");
assertEquals(expected, Optional.of("a").asSet());
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testAsSetPresentIsImmutable() {
Set<String> presentAsSet = Optional.of("a").asSet();
try {
presentAsSet.add("b");
fail();
} catch (UnsupportedOperationException ignore) {
}
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testFlatMapPresentFunctionReturnsNull() {
try {
Optional<String> unused = Optional.of("a").flatMap(new Function<String, Optional<String>>() {
@NotNull @Override public Optional<String> apply(@NotNull String s) {
return null;
}
});
fail("Should throw if Function returns null.");
} catch (NullPointerException expected) {
}
}
代码示例来源:origin: apollographql/apollo-android
@Test
public void testEqualsAndHashCodeAbsent() {
assertEquals(Optional.<String>absent(), Optional.<Integer>absent());
assertEquals(Optional.absent().hashCode(), Optional.absent().hashCode());
assertThat(Optional.absent().hashCode())
.isNotEqualTo(Optional.of(0).hashCode());
}
内容来源于网络,如有侵权,请联系作者删除!