当前位置: 首页>>代码示例>>Java>>正文


Java Functions类代码示例

本文整理汇总了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) {}
}
 
开发者ID:diffplug,项目名称:durian,代码行数:17,代码来源:FunctionsTest.java

示例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()));
}
 
开发者ID:spinnaker,项目名称:fiat,代码行数:8,代码来源:UserRolesSyncer.java

示例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"));
}
 
开发者ID:diffplug,项目名称:durian,代码行数:13,代码来源:FunctionsTest.java

示例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());
}
 
开发者ID:diffplug,项目名称:durian,代码行数:12,代码来源:FunctionsTest.java

示例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();
}
 
开发者ID:diffplug,项目名称:durian,代码行数:14,代码来源:FunctionsTest.java

示例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"));
}
 
开发者ID:diffplug,项目名称:durian,代码行数:9,代码来源:FunctionsTest.java

示例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());
}
 
开发者ID:diffplug,项目名称:durian,代码行数:12,代码来源:FunctionsTest.java

示例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));
}
 
开发者ID:diffplug,项目名称:durian,代码行数:14,代码来源:FunctionsTest.java

示例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));
}
 
开发者ID:diffplug,项目名称:durian,代码行数:14,代码来源:FunctionsTest.java

示例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));
}
 
开发者ID:diffplug,项目名称:durian,代码行数:8,代码来源:FunctionsTest.java

示例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));
}
 
开发者ID:diffplug,项目名称:durian,代码行数:10,代码来源:FunctionsTest.java

示例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"));
}
 
开发者ID:diffplug,项目名称:durian,代码行数:8,代码来源:FunctionsTest.java

示例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"));
}
 
开发者ID:diffplug,项目名称:durian,代码行数:6,代码来源:FunctionsTest.java

示例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)));
}
 
开发者ID:diffplug,项目名称:durian,代码行数:5,代码来源:FunctionsTest.java


注:本文中的com.diffplug.common.base.Functions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。