當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeRef類代碼示例

本文整理匯總了Java中io.bootique.type.TypeRef的典型用法代碼示例。如果您正苦於以下問題:Java TypeRef類的具體用法?Java TypeRef怎麽用?Java TypeRef使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeRef類屬於io.bootique.type包,在下文中一共展示了TypeRef類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: config

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Override
public <T> T config(TypeRef<? extends T> type, String prefix) {

	JsonNode child = findChild(prefix);

	JavaType jacksonType = typeFactory.constructType(type.getType());

	try {
		return mapper.readValue(new TreeTraversingParser(child, mapper), jacksonType);
	}
	// TODO: implement better exception handling. See ConfigurationFactory
	// in Dropwizard for inspiration
	catch (IOException e) {
		throw new RuntimeException("Error creating config", e);
	}
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:17,代碼來源:JsonNodeConfigurationFactory.java

示例2: testCompile_Map

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testCompile_Map() {

    TypeRef<Map<String, BigDecimal>> tr1 = new TypeRef<Map<String, BigDecimal>>() {
    };

    ConfigMapMetadata md = (ConfigMapMetadata) createCompiler(t -> Stream.empty())
            .compile("prefix", tr1.getType());

    assertNotNull(md);
    assertEquals("prefix", md.getName());
    assertEquals(tr1.getType(), md.getType());

    assertEquals(String.class, md.getKeysType());
    assertEquals(BigDecimal.class, md.getValuesType().getType());
    assertEquals(ConfigValueMetadata.class, md.getValuesType().getClass());
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:18,代碼來源:ConfigMetadataCompilerTest.java

示例3: testDIOnOptionConfig

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testDIOnOptionConfig() {

    Function<String, String> configReader =
            arg -> {
                BQRuntime runtime = runtimeFactory.app(arg)
                        .module(b -> BQCoreModule.extend(b)
                                .addConfigOnOption("opt", "classpath:io/bootique/diconfig1.yml")
                                .addConfigOnOption("opt", "classpath:io/bootique/diconfig2.yml")
                                .addOption(OptionMetadata.builder("opt").build()))
                        .createRuntime();

                Map<String, Integer> config =
                        runtime.getInstance(ConfigurationFactory.class)
                                .config(new TypeRef<Map<String, Integer>>() {
                                }, "");

                return config.toString();
            };

    assertEquals("{}", configReader.apply(""));
    assertEquals("{a=1, b=2, c=3}", configReader.apply("--opt"));
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:24,代碼來源:Bootique_ConfigurationIT.java

示例4: testDIOnOptionConfig_OverrideWithOption

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testDIOnOptionConfig_OverrideWithOption() {

    Function<String, String> configReader =
            arg -> {
                BQRuntime runtime = runtimeFactory.app(arg)
                        .module(b -> BQCoreModule.extend(b)
                                .addConfigOnOption("opt", "classpath:io/bootique/diconfig1.yml")
                                .addConfigOnOption("opt", "classpath:io/bootique/diconfig2.yml")
                                .addOption("a", "opt"))
                        .createRuntime();

                return runtime.getInstance(ConfigurationFactory.class)
                        .config(new TypeRef<Map<String, Integer>>() {
                        }, "").toString();
            };

    assertEquals("{}", configReader.apply(""));
    assertEquals("{a=8, b=2, c=3}", configReader.apply("--opt=8"));
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:21,代碼來源:Bootique_ConfigurationIT.java

示例5: testList_MultiLevel

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testList_MultiLevel() {

	List<List<Object>> l = factory("-\n  - SS\n  - 55\n-\n  - X").config(new TypeRef<List<List<Object>>>() {
	}, "");

	assertNotNull(l);
	assertEquals(2, l.size());

	List<Object> sl1 = l.get(0);
	assertEquals(2, sl1.size());
	assertEquals("SS", sl1.get(0));
	assertEquals(55, sl1.get(1));

	List<Object> sl2 = l.get(1);
	assertEquals(1, sl2.size());
	assertEquals("X", sl2.get(0));
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:19,代碼來源:JsonNodeConfigurationFactoryTest.java

示例6: createDataSource

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Singleton
@Provides
public DataSourceFactory createDataSource(
        ConfigurationFactory configFactory,
        BootLogger bootLogger,
        ShutdownManager shutdownManager,
        Set<DataSourceListener> listeners,
        Injector injector) {

    Map<String, ManagedDataSourceFactory> configs = configFactory
            .config(new TypeRef<Map<String, ManagedDataSourceFactory>>() {
            }, configPrefix);

    LazyDataSourceFactory factory = new LazyDataSourceFactoryFactory(configs).create(injector, listeners);
    shutdownManager.addShutdownHook(() -> {
        bootLogger.trace(() -> "shutting down LazyDataSourceFactory...");
        factory.shutdown();
    });

    return factory;
}
 
開發者ID:bootique,項目名稱:bootique-jdbc,代碼行數:22,代碼來源:JdbcModule.java

示例7: createJobRegistry

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Provides
@Singleton
JobRegistry createJobRegistry(
        Set<Job> jobs,
        Set<JobListener> jobListeners,
        Scheduler scheduler,
        ConfigurationFactory configFactory) {

    TypeRef<Map<String, JobDefinition>> ref = new TypeRef<Map<String, JobDefinition>>() {
    };
    Map<String, JobDefinition> configuredDefinitions = configFactory.config(ref, "jobs");

    return new DefaultJobRegistry(jobs, configuredDefinitions, scheduler, jobListeners);
}
 
開發者ID:bootique,項目名稱:bootique-job,代碼行數:15,代碼來源:JobModule.java

示例8: testEmptyConfig

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testEmptyConfig() {
    BQRuntime runtime = runtimeFactory.app("--config=src/test/resources/io/bootique/empty.yml").createRuntime();

    Map<String, String> config = runtime.getInstance(ConfigurationFactory.class)
            .config(new TypeRef<Map<String, String>>() {
            }, "");
    assertEquals("{}", config.toString());
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:10,代碼來源:Bootique_ConfigurationIT.java

示例9: testConfigEmptyConfig

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testConfigEmptyConfig() {
    BQRuntime runtime = runtimeFactory.app("--config=src/test/resources/io/bootique/test1.yml",
            "--config=src/test/resources/io/bootique/empty.yml").createRuntime();

    Map<String, String> config = runtime.getInstance(ConfigurationFactory.class)
            .config(new TypeRef<Map<String, String>>() {
            }, "");
    assertEquals("{a=b}", config.toString());
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:11,代碼來源:Bootique_ConfigurationIT.java

示例10: testDIConfig

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testDIConfig() {

    BQRuntime runtime = runtimeFactory.app()
            .module(b -> BQCoreModule.extend(b)
                    .addConfig("classpath:io/bootique/diconfig1.yml")
                    .addConfig("classpath:io/bootique/diconfig2.yml"))
            .createRuntime();

    Map<String, String> config = runtime.getInstance(ConfigurationFactory.class)
            .config(new TypeRef<Map<String, String>>() {
            }, "");
    assertEquals("{a=1, b=2, c=3}", config.toString());
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:15,代碼來源:Bootique_ConfigurationIT.java

示例11: testDIConfig_VsCliOrder

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testDIConfig_VsCliOrder() {

    BQRuntime runtime = runtimeFactory.app("-c", "classpath:io/bootique/cliconfig.yml")
            .module(b -> BQCoreModule.extend(b)
                    .addConfig("classpath:io/bootique/diconfig1.yml")
                    .addConfig("classpath:io/bootique/diconfig2.yml"))
            .createRuntime();

    Map<String, Integer> config = runtime.getInstance(ConfigurationFactory.class)
            .config(new TypeRef<Map<String, Integer>>() {
            }, "");
    assertEquals("{a=5, b=2, c=6}", config.toString());
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:15,代碼來源:Bootique_ConfigurationIT.java

示例12: testConfigConfig

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testConfigConfig() {
    BQRuntime runtime = runtimeFactory.app("--config=src/test/resources/io/bootique/test1.yml",
            "--config=src/test/resources/io/bootique/test2.yml").createRuntime();

    Map<String, String> config = runtime.getInstance(ConfigurationFactory.class)
            .config(new TypeRef<Map<String, String>>() {
            }, "");
    assertEquals("{a=e, c=d}", config.toString());
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:11,代碼來源:Bootique_ConfigurationIT.java

示例13: testConfigConfig_Reverse

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testConfigConfig_Reverse() {
    BQRuntime runtime = runtimeFactory.app("--config=src/test/resources/io/bootique/test2.yml",
            "--config=src/test/resources/io/bootique/test1.yml").createRuntime();

    Map<String, String> config = runtime.getInstance(ConfigurationFactory.class)
            .config(new TypeRef<Map<String, String>>() {
            }, "");
    assertEquals("{a=b, c=d}", config.toString());
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:11,代碼來源:Bootique_ConfigurationIT.java

示例14: testConfigEnvOverrides

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testConfigEnvOverrides() {
    BQRuntime runtime = runtimeFactory.app("--config=src/test/resources/io/bootique/test2.yml").var("BQ_A", "F")
            .createRuntime();

    Map<String, String> config = runtime.getInstance(ConfigurationFactory.class)
            .config(new TypeRef<Map<String, String>>() {
            }, "");

    assertEquals("{a=F, c=d}", config.toString());
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:12,代碼來源:Bootique_ConfigurationIT.java

示例15: testList_SingleLevel

import io.bootique.type.TypeRef; //導入依賴的package包/類
@Test
public void testList_SingleLevel() {

	List<Object> l = factory("- SS\n- 55").config(new TypeRef<List<Object>>() {
	}, "");

	assertNotNull(l);
	assertEquals("SS", l.get(0));
	assertEquals(55, l.get(1));
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:11,代碼來源:JsonNodeConfigurationFactoryTest.java


注:本文中的io.bootique.type.TypeRef類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。