当前位置: 首页>>代码示例>>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;未经允许,请勿转载。