當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。