本文整理汇总了Java中org.yaml.snakeyaml.DumperOptions.setExplicitStart方法的典型用法代码示例。如果您正苦于以下问题:Java DumperOptions.setExplicitStart方法的具体用法?Java DumperOptions.setExplicitStart怎么用?Java DumperOptions.setExplicitStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.yaml.snakeyaml.DumperOptions
的用法示例。
在下文中一共展示了DumperOptions.setExplicitStart方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEmitNoTags
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testEmitNoTags() {
TestObject result = parseObject(Util.getLocalResource("ruby/ruby1.yaml"));
DumperOptions options = new DumperOptions();
options.setExplicitStart(true);
Yaml yaml2 = new Yaml(options);
String output = yaml2.dumpAsMap(result);
assertFalse("No tags expected.", output.contains("Sub1"));
// System.out.println(output);
// parse back. Without tags it shall still work
Yaml beanLoader = new Yaml();
TestObject result2 = beanLoader.loadAs(output, TestObject.class);
assertEquals(0, result2.getSub1().getAtt2());
assertEquals("MyString", result2.getSub2().getAtt1());
assertEquals(1, result2.getSub2().getAtt2().size());
assertEquals(12345, result2.getSub2().getAtt3());
}
示例2: testEmitWithTags
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testEmitWithTags() {
TestObject result = parseObject(Util.getLocalResource("ruby/ruby1.yaml"));
DumperOptions options = new DumperOptions();
options.setExplicitStart(true);
Representer repr = new Representer();
repr.addClassTag(TestObject.class, new Tag("!ruby/object:Test::Module::Object"));
repr.addClassTag(Sub1.class, new Tag("!ruby/object:Test::Module::Sub1"));
repr.addClassTag(Sub2.class, new Tag("!ruby/object:Test::Module::Sub2"));
Yaml yaml2 = new Yaml(repr, options);
String output = yaml2.dump(result);
// System.out.println(output);
assertTrue("Tags must be present.",
output.startsWith("--- !ruby/object:Test::Module::Object"));
assertTrue("Tags must be present: " + output,
output.contains("!ruby/object:Test::Module::Sub1"));
assertTrue("Tags must be present.", output.contains("!ruby/object:Test::Module::Sub2"));
// parse back.
TestObject result2 = parseObject(output);
assertEquals(0, result2.getSub1().getAtt2());
assertEquals("MyString", result2.getSub2().getAtt1());
assertEquals(1, result2.getSub2().getAtt2().size());
assertEquals(12345, result2.getSub2().getAtt3());
}
示例3: testEmitWithTags2WithoutTagForParentJavabean
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testEmitWithTags2WithoutTagForParentJavabean() {
TestObject result = parseObject(Util.getLocalResource("ruby/ruby1.yaml"));
DumperOptions options = new DumperOptions();
options.setExplicitStart(true);
Representer repr = new Representer();
repr.addClassTag(Sub1.class, new Tag("!ruby/object:Test::Module::Sub1"));
repr.addClassTag(Sub2.class, new Tag("!ruby/object:Test::Module::Sub2"));
Yaml yaml2 = new Yaml(repr, options);
String output = yaml2.dump(result);
// System.out.println(output);
assertTrue("Tags must be present.",
output.startsWith("--- !!org.yaml.snakeyaml.ruby.TestObject"));
assertTrue("Tags must be present: " + output,
output.contains("!ruby/object:Test::Module::Sub1"));
assertTrue("Tags must be present.", output.contains("!ruby/object:Test::Module::Sub2"));
// parse back.
TestObject result2 = parseObject(output);
assertEquals(0, result2.getSub1().getAtt2());
assertEquals("MyString", result2.getSub2().getAtt1());
assertEquals(1, result2.getSub2().getAtt2().size());
assertEquals(12345, result2.getSub2().getAtt3());
}
示例4: testDumpMany
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testDumpMany() {
List<Integer> docs = new ArrayList<Integer>();
for (int i = 1; i < 4; i++) {
docs.add(i);
}
DumperOptions options = new DumperOptions();
options.setExplicitStart(true);
Yaml yaml = new Yaml(options);
String result = yaml.dumpAll(docs.iterator());
assertNotNull(result);
assertTrue(result.contains("--- 2"));
}
示例5: executeArguments
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
/**
* This method takes a set of command line arguments and tries to construct
* OptimizationParameters and StatisticsParameters from it. It will use defaults if
* not otherwise configured.
*
* @param args Command line arguments
*/
private static void executeArguments(String[] args) {
InterfaceOptimizationParameters parameters = OptimizationBuilder.parseOptimizerArguments(args);
InterfaceStatisticsParameters statisticsParameters = OptimizationBuilder.parseStatisticsArguments(args);
InterfaceTerminator terminator = parameters.getTerminator();
InterfaceOptimizer optimizer = parameters.getOptimizer();
InterfaceOptimizationProblem problem = parameters.getProblem();
LinkedHashMap<String, Object> optimizationLog = new LinkedHashMap<>();
// Meta parameters
optimizationLog.put("populationSize", parameters.getOptimizer().getPopulation().getTargetSize());
optimizationLog.put("numberOfRuns", statisticsParameters.getMultiRuns());
optimizationLog.put("seed", parameters.getRandomSeed());
optimizationLog.put("problem", parameters.getProblem());
CommandLineStatistics yamlStatistics = new CommandLineStatistics(statisticsParameters);
/**
* Runs optimization
*/
Processor optimizationProcessor = new Processor(yamlStatistics, parameters);
optimizationProcessor.setSaveParams(false);
optimizationProcessor.startOptimization();
optimizationProcessor.runOptimizationOnce();
/**
* Get run statistics
*/
optimizationLog.put("runs", yamlStatistics.getRuns());
/**
* Yaml configuration
*/
DumperOptions options = new DumperOptions();
options.setExplicitStart(true);
options.setExplicitEnd(true);
Yaml yaml = new Yaml();
System.out.println(yaml.dump(optimizationLog));
}