本文整理汇总了Java中com.diffplug.common.base.Functions类的典型用法代码示例。如果您正苦于以下问题:Java Functions类的具体用法?Java Functions怎么用?Java Functions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Functions类属于com.diffplug.common.base包,在下文中一共展示了Functions类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testForMapWithoutDefault
import com.diffplug.common.base.Functions; //导入依赖的package包/类
public void testForMapWithoutDefault() {
Map<String, Integer> map = Maps.newHashMap();
map.put("One", 1);
map.put("Three", 3);
map.put("Null", null);
Function<String, Integer> function = Functions.forMap(map);
assertEquals(1, function.apply("One").intValue());
assertEquals(3, function.apply("Three").intValue());
assertNull(function.apply("Null"));
try {
function.apply("Two");
fail();
} catch (IllegalArgumentException expected) {}
}
示例2: getServiceAccountsAsMap
import com.diffplug.common.base.Functions; //导入依赖的package包/类
private Map<String, UserPermission> getServiceAccountsAsMap() {
return serviceAccountProvider
.getAll()
.stream()
.map(ServiceAccount::toUserPermission)
.collect(Collectors.toMap(UserPermission::getId, Functions.identity()));
}
示例3: testForMapWithDefault
import com.diffplug.common.base.Functions; //导入依赖的package包/类
public void testForMapWithDefault() {
Map<String, Integer> map = Maps.newHashMap();
map.put("One", 1);
map.put("Three", 3);
map.put("Null", null);
Function<String, Integer> function = Functions.forMap(map, 42);
assertEquals(1, function.apply("One").intValue());
assertEquals(42, function.apply("Two").intValue());
assertEquals(3, function.apply("Three").intValue());
assertNull(function.apply("Null"));
}
示例4: testForMapWithDefault_includeSerializable
import com.diffplug.common.base.Functions; //导入依赖的package包/类
@GwtIncompatible("SerializableTester")
public void testForMapWithDefault_includeSerializable() {
Map<String, Integer> map = Maps.newHashMap();
map.put("One", 1);
map.put("Three", 3);
Function<String, Integer> function = Functions.forMap(map, 42);
assertEquals(1, function.apply("One").intValue());
assertEquals(42, function.apply("Two").intValue());
assertEquals(3, function.apply("Three").intValue());
}
示例5: testForMapWithDefault_null
import com.diffplug.common.base.Functions; //导入依赖的package包/类
public void testForMapWithDefault_null() {
ImmutableMap<String, Integer> map = ImmutableMap.of("One", 1);
Function<String, Integer> function = Functions.forMap(map, null);
assertEquals((Integer) 1, function.apply("One"));
assertNull(function.apply("Two"));
// check basic sanity of equals and hashCode
new EqualsTester()
.addEqualityGroup(function)
.addEqualityGroup(Functions.forMap(map, 1))
.testEquals();
}
示例6: testForMapWithDefault_null_compareWithSerializable
import com.diffplug.common.base.Functions; //导入依赖的package包/类
@GwtIncompatible("SerializableTester")
public void testForMapWithDefault_null_compareWithSerializable() {
ImmutableMap<String, Integer> map = ImmutableMap.of("One", 1);
Function<String, Integer> function = Functions.forMap(map, null);
assertEquals((Integer) 1, function.apply("One"));
assertNull(function.apply("Two"));
}
示例7: testForMapWildCardWithDefault
import com.diffplug.common.base.Functions; //导入依赖的package包/类
public void testForMapWildCardWithDefault() {
Map<String, Integer> map = Maps.newHashMap();
map.put("One", 1);
map.put("Three", 3);
Number number = Double.valueOf(42);
Function<String, Number> function = Functions.forMap(map, number);
assertEquals(1, function.apply("One").intValue());
assertEquals(number, function.apply("Two"));
assertEquals(3L, function.apply("Three").longValue());
}
示例8: testComposeOfFunctionsIsAssociative
import com.diffplug.common.base.Functions; //导入依赖的package包/类
public void testComposeOfFunctionsIsAssociative() {
Map<Float, String> m = ImmutableMap.of(
4.0f, "A", 3.0f, "B", 2.0f, "C", 1.0f, "D");
Function<? super Integer, Boolean> h = Functions.constant(Boolean.TRUE);
Function<? super String, Integer> g = new HashCodeFunction();
Function<Float, String> f = Functions.forMap(m, "F");
Function<Float, Boolean> c1 = Functions.compose(Functions.compose(h, g), f);
Function<Float, Boolean> c2 = Functions.compose(h, Functions.compose(g, f));
assertEquals(c1.apply(1.0f), c2.apply(1.0f));
assertEquals(c1.apply(5.0f), c2.apply(5.0f));
}
示例9: testComposeOfPredicateAndFunctionIsAssociative
import com.diffplug.common.base.Functions; //导入依赖的package包/类
public void testComposeOfPredicateAndFunctionIsAssociative() {
Map<Float, String> m = ImmutableMap.of(
4.0f, "A", 3.0f, "B", 2.0f, "C", 1.0f, "D");
Predicate<? super Integer> h = Predicates.equalTo(42);
Function<? super String, Integer> g = new HashCodeFunction();
Function<Float, String> f = Functions.forMap(m, "F");
Predicate<Float> p1 = Predicates.compose(Predicates.compose(h, g), f);
Predicate<Float> p2 = Predicates.compose(h, Functions.compose(g, f));
assertEquals(p1.test(1.0f), p2.test(1.0f));
assertEquals(p1.test(5.0f), p2.test(5.0f));
}
示例10: testForPredicate
import com.diffplug.common.base.Functions; //导入依赖的package包/类
public void testForPredicate() {
Function<Object, Boolean> alwaysTrue = Functions.forPredicate(Predicates.alwaysTrue());
Function<Object, Boolean> alwaysFalse = Functions.forPredicate(Predicates.alwaysFalse());
assertTrue(alwaysTrue.apply(0));
assertFalse(alwaysFalse.apply(0));
}
示例11: testConstant
import com.diffplug.common.base.Functions; //导入依赖的package包/类
public void testConstant() {
Function<Object, Object> f = Functions.<Object> constant("correct");
assertEquals("correct", f.apply(new Object()));
assertEquals("correct", f.apply(null));
Function<Object, String> g = Functions.constant(null);
assertEquals(null, g.apply(2));
assertEquals(null, g.apply(null));
}
示例12: testForSupplier
import com.diffplug.common.base.Functions; //导入依赖的package包/类
public void testForSupplier() {
Supplier<Integer> supplier = new CountingSupplier();
Function<Object, Integer> function = Functions.forSupplier(supplier);
assertEquals(1, (int) function.apply(null));
assertEquals(2, (int) function.apply("foo"));
}
示例13: testIdentity_same
import com.diffplug.common.base.Functions; //导入依赖的package包/类
public void testIdentity_same() {
Function<String, String> identity = Functions.identity();
assertNull(identity.apply(null));
assertSame("foo", identity.apply("foo"));
}
示例14: testIdentity_notSame
import com.diffplug.common.base.Functions; //导入依赖的package包/类
public void testIdentity_notSame() {
Function<Long, Long> identity = Functions.identity();
assertNotSame(new Long(135135L), identity.apply(new Long(135135L)));
}