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


Java Supplier.get方法代码示例

本文整理汇总了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;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:23,代码来源:Deliver.java

示例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;
}
 
开发者ID:XDean,项目名称:Java-EX,代码行数:10,代码来源:CacheUtil.java

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

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

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

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

示例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);
}
 
开发者ID:florentw,项目名称:bench,代码行数:16,代码来源:ResourceManagerAgentTest.java

示例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;
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:16,代码来源:CommandContext.java

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

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

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

示例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";
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:11,代码来源:PrinterOfPeriod.java

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

示例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);
        }
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:29,代码来源:ArrayStatsTests.java

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


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