本文整理了Java中uk.gov.dstl.baleen.core.utils.yaml.YamlConfiguration
类的一些代码示例,展示了YamlConfiguration
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlConfiguration
类的具体详情如下:
包路径:uk.gov.dstl.baleen.core.utils.yaml.YamlConfiguration
类名称:YamlConfiguration
[英]A helper to deal with YAML files and their basic map representation.
Configuration can be accessed by a path representation e.g.:
"logging.enabled"
This class also contains helper methods to get a type safe value from the YAML configuration.
[中]处理YAML文件及其基本地图表示的助手。
可通过路径表示访问配置,例如:
"logging.enabled"
该类还包含从YAML配置获取类型安全值的帮助器方法。
代码示例来源:origin: uk.gov.dstl.baleen/baleen-core
private static YamlConfiguration createConfigurtion(Optional<File> configurationFile)
throws BaleenException {
if (configurationFile.isPresent()) {
try (InputStream is = new FileInputStream(configurationFile.get())) {
LOGGER.info("Configuration file provided {}", configurationFile.get().getAbsolutePath());
return new YamlConfiguration(configurationFile.get());
} catch (Exception ioe) {
throw new BaleenException("Unable to read configuration file", ioe);
}
} else {
LOGGER.info("No configuration file provided - default configuration will be used");
}
try {
return new YamlConfiguration();
} catch (Exception e) {
throw new BaleenException("Unable to read configuration file", e);
}
}
代码示例来源:origin: dstl/baleen
@Override
public <T> Optional<T> get(Class<T> clazz, String path) {
return Optional.ofNullable(get(clazz, path, null));
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-core
@Override
public List<Map<String, Object>> getAsListOfMaps(String path) {
return getAsList(path);
}
代码示例来源:origin: dstl/baleen
@Test
public void testReadString() throws IOException {
YamlConfiguration yc =
new YamlConfiguration("example:\n color: red\n count: 7\n list:\n - a\n - b\n - c");
assertTrue(yc.getAsList("example.list").containsAll(Arrays.asList("a", "b", "c")));
assertEquals("red", yc.get(String.class, "example.color").get());
}
代码示例来源:origin: dstl/baleen
@Test
public void testCleanTabs() throws IOException {
assertEquals(
"test: \"Hello\\tWorld!\"\n" + "testing:\n" + "- 1.. 2.. 3.. 4..\n",
new YamlConfiguration("\t\ttest: Hello\tWorld!\n\t\ttesting:\n\t\t- 1.. 2.. 3.. 4.. ")
.toString());
}
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-core
@Override
@SuppressWarnings("unchecked")
public <T> T get(String path, T defaultValue) {
Optional<Object> o = internalGet(path);
T ret = defaultValue;
if (o.isPresent()) {
try {
ret = (T) o.get();
} catch (ClassCastException cce) {
LOGGER.warn("Requested path cannot be cast to requested type", cce);
}
}
return ret;
}
代码示例来源:origin: dstl/baleen
@Test
public void testGetFirst() {
assertEquals(
"uk.gov.dstl.baleen.testing.DummyContentExtractor",
config.getFirst(String.class, "contentextractor.class", "contentextractor").get());
assertEquals(
"uk.gov.dstl.baleen.testing.DummyCollectionReader",
config.getFirst(String.class, "collectionreader.class", "collectionreader").get());
Optional<String> found = config.getFirst(String.class, MISSING_KEY, "example", "missing");
assertFalse(found.isPresent());
}
代码示例来源:origin: dstl/baleen
@Test
public void testGetAsListOfMaps() {
List<Map<String, Object>> listMap = config.getAsListOfMaps("annotators");
assertFalse(listMap.isEmpty());
}
代码示例来源:origin: dstl/baleen
@Override
public <T> T get(Class<T> clazz, String path, T defaultValue) {
Optional<Object> o = internalGet(path);
T ret = defaultValue;
if (o.isPresent()) {
try {
ret = clazz.cast(o.get());
} catch (ClassCastException cce) {
LOGGER.debug("Requested path cannot be cast to requested type", cce);
}
}
return ret;
}
代码示例来源:origin: dstl/baleen
private static YamlConfiguration createConfigurtion(Optional<File> configurationFile)
throws BaleenException {
if (configurationFile.isPresent()) {
try (InputStream is = new FileInputStream(configurationFile.get())) {
LOGGER.info("Configuration file provided {}", configurationFile.get().getAbsolutePath());
return new YamlConfiguration(configurationFile.get());
} catch (Exception ioe) {
throw new BaleenException("Unable to read configuration file", ioe);
}
} else {
LOGGER.info("No configuration file provided - default configuration will be used");
}
try {
return new YamlConfiguration();
} catch (Exception e) {
throw new BaleenException("Unable to read configuration file", e);
}
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-core
@Override
public <T> Optional<T> get(String path) {
return Optional.ofNullable(get(path, null));
}
代码示例来源:origin: dstl/baleen
@Override
public List<Map<String, Object>> getAsListOfMaps(String path) {
return getAsList(path);
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-core
@Override
@SuppressWarnings("unchecked")
public <T> List<T> getAsList(String path) {
Optional<Object> o = internalGet(path);
List<T> ret = Collections.emptyList();
if (o.isPresent() && o.get() instanceof List) {
try {
ret = (List<T>) o.get();
} catch (ClassCastException cce) {
LOGGER.warn("Requested path is not a list of the correct type", cce);
}
} else {
LOGGER.debug(
"Path [{}] not found, or isn't an instanceof List - an empty list will be returned",
path);
}
return ret;
}
代码示例来源:origin: dstl/baleen
BaleenManager baleen = new BaleenManager(new YamlConfiguration(yaml));
if (dryRun) {
baleen.run(manager -> LOGGER.info("Dry run mode: closing immediately"));
代码示例来源:origin: dstl/baleen
@Override
public <T> Optional<T> getFirst(Class<T> clazz, String... paths) {
for (String path : Arrays.asList(paths)) {
Optional<T> optional = get(clazz, path);
if (optional.isPresent()) {
return optional;
}
}
return Optional.empty();
}
代码示例来源:origin: dstl/baleen
@Test
public void testGetAsList() {
List<String> list = config.getAsList(LIST_KEY);
assertTrue(list.containsAll(Arrays.asList("a", "b", "c")));
list = config.getAsList(MISSING_KEY);
assertTrue(list.isEmpty());
}
代码示例来源:origin: dstl/baleen
@Override
@SuppressWarnings("unchecked")
public <T> List<T> getAsList(String path) {
Optional<Object> o = internalGet(path);
List<T> ret = Collections.emptyList();
if (o.isPresent() && o.get() instanceof List) {
try {
ret = (List<T>) o.get();
} catch (ClassCastException cce) {
LOGGER.warn("Requested path is not a list of the correct type", cce);
}
} else {
LOGGER.debug(
"Path [{}] not found, or isn't an instanceof List - an empty list will be returned",
path);
}
return ret;
}
代码示例来源:origin: dstl/baleen
@Before
public void setup() throws IOException {
config = new YamlConfiguration(YamlConfigurationTest.class, YAMLCONFIGURATION_YAML);
}
代码示例来源:origin: dstl/baleen
@Test
public void testGet() {
assertTrue(config.get(Integer.class, INT_KEY).isPresent());
assertEquals(7, (int) config.get(Integer.class, INT_KEY).get());
assertFalse(config.get(Object.class, MISSING_KEY).isPresent());
}
代码示例来源:origin: dstl/baleen
@Test
public void testNonExistentFile() {
try {
new YamlConfiguration(new File("missing.yaml"));
} catch (IOException ioe) {
return;
}
fail("Didn't throw expected IOException");
}
内容来源于网络,如有侵权,请联系作者删除!