本文整理匯總了Java中java.util.function.Supplier.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Supplier.get方法的具體用法?Java Supplier.get怎麽用?Java Supplier.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.function.Supplier
的用法示例。
在下文中一共展示了Supplier.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execRun
import java.util.function.Supplier; //導入方法依賴的package包/類
/**
* @param supplier
* @param runCls
* @param <T>
* @return
*/
static <T> T execRun(final Supplier<T> supplier,
final Class<? extends ZeroRunException> runCls,
final Object... args) {
T ret = null;
try {
ret = supplier.get();
} catch (final Throwable ex) {
final Object[] argument = ArrayUtil.add(args, ex);
final ZeroRunException error = Instance.instance(
runCls, argument);
if (null != error) {
throw error;
}
}
return ret;
}
示例2: cacheWeak
import java.util.function.Supplier; //導入方法依賴的package包/類
public static <V> V cacheWeak(Object owner, Object key, Supplier<V> factory) {
WeakReference<V> ref = cache(owner, key, () -> new WeakReference<>(factory.get()));
V v = ref.get();
if (v == null) {
v = factory.get();
set(owner, key, new WeakReference<>(v));
}
return v;
}
示例3: testSupplier
import java.util.function.Supplier; //導入方法依賴的package包/類
@Test
public void testSupplier() {
final String prefix = "trellis:repository/";
final Supplier<String> supplier = new UUIDGenerator().getSupplier(prefix);
final String id1 = supplier.get();
final String id2 = supplier.get();
assertTrue(id1.startsWith(prefix));
assertTrue(id2.startsWith(prefix));
assertFalse(id1.equals(id2));
}
示例4: Options
import java.util.function.Supplier; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected Options(Map<String, Object> data) throws CommandBuildException {
super(data);
try {
Supplier<Collection<E>> supplier = (Supplier<Collection<E>>) data.get(SUPPLIER);
Objects.requireNonNull(supplier, "Missing supplier");
this.contents = supplier.get();
this.factory = (Function<String, E>) data.get(FACTORY);
} catch (Throwable t) {
throw new CommandBuildException("Failed to build options", t);
}
}
示例5: agent_registration_complete
import java.util.function.Supplier; //導入方法依賴的package包/類
@Theory
public void agent_registration_complete(final Supplier supplier) throws Exception {
BenchRule benchRule = (BenchRule) supplier.get();
before(benchRule);
assertThat(agentRegistry.all().size(), is(1));
RegisteredAgent registeredAgent = agentRegistry.all().iterator().next();
assertThat(registeredAgent.getAgentKey(), is(agent.getKey()));
assertTrue(registeredAgent.getCreationTime() > 0);
assertNotNull(registeredAgent.getSystemConfig());
after(benchRule);
}
示例6: delegate
import java.util.function.Supplier; //導入方法依賴的package包/類
protected <T> T delegate(ItemStack stack, Function<ItemArmor, T> action, Supplier<T> def) {
if (stack != null) {
return this.delegate(new RandoresItemData(stack), action, def);
} else {
return def.get();
}
}
示例7: create_and_close_embedded_actor_on_agent
import java.util.function.Supplier; //導入方法依賴的package包/類
@Theory
public void create_and_close_embedded_actor_on_agent(final Supplier supplier) throws Exception {
BenchRule benchRule = (BenchRule) supplier.get();
before(benchRule);
List<String> preferredHosts = new ArrayList<>();
ActorSync sync = createActorWith(preferredHosts);
sync.assertActorCreated();
resourceManager.closeActor(DUMMY_ACTOR);
sync.assertActorClosed();
assertThat(actorRegistry.all().size(), is(0));
after(benchRule);
}
示例8: get
import java.util.function.Supplier; //導入方法依賴的package包/類
/**
* Gets a value stored before by key
*
* @param key The key
* @param supplier The supplier if the value does not exist
* @return The value
*/
public <V> V get(String key, Supplier<V> supplier) {
Object o = CONTEXT_CACHE.get(getSendersUniqueId(), getCommand().getLabel() + ":" + key);
if(o == null && supplier != null) {
o = supplier.get();
this.set(o);
}
return (V) o;
}
示例9: notNullOrEmpty
import java.util.function.Supplier; //導入方法依賴的package包/類
public static <T extends ContractBrokenException, E> Collection<E> notNullOrEmpty(Collection<E> collection, Supplier<T> exceptionSupplier) {
if (isEmpty(collection)) {
throw exceptionSupplier.get();
}
return collection;
}
示例10: getParsedQueries
import java.util.function.Supplier; //導入方法依賴的package包/類
@Override
public ParsedQueries getParsedQueries(SourceId sourceId, Supplier<ParsedQueries> queriesSupplier) {
if (parsedCache == null) {
return queriesSupplier.get();
} else {
return parsedCache.get(sourceId, (k) -> queriesSupplier.get());
}
}
示例11: createTabWithStackIcon
import java.util.function.Supplier; //導入方法依賴的package包/類
private static CreativeTabs createTabWithStackIcon(final String label, final Supplier<ItemStack> iconSupplier) {
return new CreativeTabs(GenesisMod.MOD_ID + "." + label) {
@SideOnly(Side.CLIENT)
@Override
public ItemStack getTabIconItem() {
return iconSupplier.get();
}
};
}
示例12: apply
import java.util.function.Supplier; //導入方法依賴的package包/類
@Override
public final String apply(Period input) {
if (input == null) {
final Supplier<String> nullValue = getNullValue();
return nullValue != null ? nullValue.get() : "null";
} else {
final int days = input.getDays();
return days + "D";
}
}
示例13: lateBindingTestWithForEach
import java.util.function.Supplier; //導入方法依賴的package包/類
@Test(dataProvider = "Source")
public <T> void lateBindingTestWithForEach(String description, Supplier<Source<T>> ss) {
Source<T> source = ss.get();
Collection<T> c = source.asCollection();
Spliterator<T> s = c.spliterator();
source.update();
Set<T> r = new HashSet<>();
s.forEachRemaining(r::add);
assertEquals(r, new HashSet<>(c));
}
示例14: testCumSumOfDoublesWithNans
import java.util.function.Supplier; //導入方法依賴的package包/類
@Test(dataProvider = "styles")
public void testCumSumOfDoublesWithNans(ArrayStyle style) {
final Random random = new Random();
final Supplier<Array<Double>> factory = () -> {
switch (style) {
case DENSE: return Array.of(Double.class, 10000).applyDoubles(v -> random.nextDouble() * 10d);
case SPARSE: return Array.of(Double.class, 10000, 0.8f).applyDoubles(v -> random.nextDouble() * 10d);
case MAPPED: return Array.map(Double.class, 10000).applyDoubles(v -> random.nextDouble() * 10d);
default: throw new IllegalArgumentException("Unsupported style: " + style);
}
};
final Array<Double> source = factory.get();
source.setDouble(0, Double.NaN);
source.setDouble(25, Double.NaN);
final Array<Double> cumSum = source.cumSum();
for (int i=0; i<source.length(); ++i) {
final double actual = cumSum.getDouble(i);
final double expected = source.stats(0, i+1).sum().doubleValue();
if (i == 0) {
Assert.assertTrue(Double.isNaN(actual));
} else if (i == 25) {
final double prior = source.stats(0, i).sum().doubleValue();
Assert.assertEquals(actual, prior, "Values match at index " + i);
} else {
Assert.assertEquals(actual, expected, "Values match at index " + i);
}
}
}
示例15: ne
import java.util.function.Supplier; //導入方法依賴的package包/類
public static <U, T extends RuntimeException> void ne(U o1, U o2, Supplier<T> supplier) {
if (Objects.equals(o1, o2)) {
throw supplier.get();
}
}