本文整理汇总了Java中org.ho.yaml.Yaml类的典型用法代码示例。如果您正苦于以下问题:Java Yaml类的具体用法?Java Yaml怎么用?Java Yaml使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Yaml类属于org.ho.yaml包,在下文中一共展示了Yaml类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Configuration
import org.ho.yaml.Yaml; //导入依赖的package包/类
public Configuration(File file) {
this.file = file;
Map<String, Object> configTemp;
try {
configTemp = Yaml.loadType(file, LinkedHashMap.class);
} catch (Exception e) {
configTemp = new HashMap<>();
if (file.equals(CONFIG_FILE)) {
for (ConfigKey configKey : ConfigKey.values()) {
configTemp.put(configKey.name(), configKey.value());
}
logger.error("can't load config {}", e.getMessage());
try {
logger.info("Creating default config");
Yaml.dump(configTemp, file);
} catch (FileNotFoundException ee) {
logger.warn("Error saving config", ee);
}
}
}
config = configTemp;
}
示例2: readSingleSchedulerConfig
import org.ho.yaml.Yaml; //导入依赖的package包/类
public static Map<String, Object> readSingleSchedulerConfig(String filePath) {
Map<String, Object> res = new HashMap<String, Object>();
File file = new File(filePath);
try {
Map<String, Object> map = Yaml.loadType(file, HashMap.class);
for(Map.Entry<String, Object> entry : map.entrySet()) {
if(entry.getValue() instanceof Map)
continue;
res.put(entry.getKey(), entry.getValue());
}
} catch(FileNotFoundException fe) {
fe.printStackTrace();
}
return res;
}
示例3: testWebSiteExample2
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testWebSiteExample2() throws Exception{
String yamlText =
"--- \n" +
"date: 11/29/2005\n" +
"receipts:\n" +
" - store: ken stanton music\n" +
" category: entertainment\n" +
" description: saxophone repair\n" +
" total: 382.00\n" +
" - store: walmart\n" +
" category: groceries\n" +
" total: 14.26";
Entry entry = Yaml.loadType(yamlText, Entry.class);
assertEquals("11/29/2005", entry.getDate());
assertEquals(2, entry.getReceipts().length);
assertEquals("ken stanton music", entry.getReceipts()[0].getStore());
assertEquals("groceries", entry.getReceipts()[1].getCategory());
assertEquals(382.00, entry.getReceipts()[0].getTotal());
}
示例4: testWebSiteExample2WithRealDate
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testWebSiteExample2WithRealDate() throws Exception{
String yamlText =
"--- \n" +
"date: 11/29/2005\n" +
"receipts:\n" +
" - store: ken stanton music\n" +
" category: entertainment\n" +
" description: saxophone repair\n" +
" total: 382.00\n" +
" - store: walmart\n" +
" category: groceries\n" +
" total: 14.26";
Entry2 entry = Yaml.loadType(yamlText, Entry2.class);
assertEquals(new Date("11/29/2005"), entry.getDate());
assertEquals(2, entry.getReceipts().length);
assertEquals("ken stanton music", entry.getReceipts()[0].getStore());
assertEquals("groceries", entry.getReceipts()[1].getCategory());
assertEquals(382.00, entry.getReceipts()[0].getTotal());
}
示例5: testSkimoInlinedList
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testSkimoInlinedList(){
String yamlText =
"---\n" +
"arrays:\n" +
" - &1\n" +
" dims:\n" +
" - 10\n" +
" id: 1610612737\n" +
" name: a\n" +
"cacheline: -1\n" +
"context:\n" +
" constraints:\n" +
" -\n" +
" - [1, 1, 0]\n" +
" - [1, -1, 2]\n" +
" dim: 0\n" +
" params:\n" +
" - &2\n" +
" name: n\n";
PDG pdg = Yaml.loadType(yamlText, PDG.class);
assertEquals("-1", pdg.cacheline);
}
示例6: testSkimoIgnoreTransfers
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testSkimoIgnoreTransfers(){
String yamlText =
"--- !perl/PDG\n" +
"arrays:\n" +
" - &1\n" +
" dims:\n" +
" - 10\n" +
" id: 1610612737\n" +
" name: a\n" +
"cacheline: -1\n" +
"context: !perl/PDG::UnionSet\n" +
" constraints:\n" +
" - !perl/PDL::Matrix\n" +
" - [1, 1, 0]\n" +
" - [1, -1, 2]\n" +
" dim: 0\n" +
" params:\n" +
" - &2\n" +
" name: n\n";
PDG pdg = Yaml.loadType(yamlText, PDG.class);
assertEquals("-1", pdg.cacheline);
}
示例7: testSkimoArray
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testSkimoArray(){
String yamlText =
"---\n" +
"context:\n" +
" constraints:\n" +
" -\n" +
" - [1, 1, 0]\n" +
" - [1, -1, 2]\n" +
" dim: 0";
PDG pdg = Yaml.loadType(yamlText, PDG.class);
assertEquals(pdg.context.dim, 0);
assertEquals(pdg.context.constraints[0][0][0], 1);
assertEquals(pdg.context.constraints[0][0][1], 1);
assertEquals(pdg.context.constraints[0][0][2], 0);
assertEquals(pdg.context.constraints[0][1][0], 1);
assertEquals(pdg.context.constraints[0][1][1], -1);
assertEquals(pdg.context.constraints[0][1][2], 2);
}
示例8: testAnchorIgnored
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testAnchorIgnored(){
String yamlText =
"---\n" +
"ignored:\n" +
" - &1\n" +
" dims: []\n" +
" id: 1610612737\n" +
" name: a\n" +
"arrays:\n" +
" - *1";
try {
PDG pdg = Yaml.loadType(yamlText, PDG.class);
assertEquals(pdg.arrays[0].name, "a");
throw new Error("This should have failed.");
} catch (YamlException e) {
}
}
示例9: testDateArray
import org.ho.yaml.Yaml; //导入依赖的package包/类
/**
* Test that the parser can save/load an array of formatted dates
*
* @author Steve Leach
*/
public void testDateArray()
{
YamlConfig.getDefaultConfig().setDateFormat(DateWrapper.DATEFORMAT_YAML);
Date[] dates = new Date[3];
dates[0] = TestDateTimeParser.getDate( 2004, 10, 01, 10, 35, 21 );
dates[1] = TestDateTimeParser.getDate( 1900, 01, 10, 10, 35, 21 );
dates[2] = TestDateTimeParser.getDate( 1940, 04, 04, 0, 0, 0 );
String s = Yaml.dump(dates,true);
Date[] dates2 = Yaml.loadType( s, Date[].class );
YamlConfig.getDefaultConfig().setDateFormat(null);
for (int i = 0; i < dates.length; i++)
{
assertEquals( dates[i], dates2[i], TestDateTimeParser.DELTA_30SEC );
}
}
示例10: testDatesInBeans
import org.ho.yaml.Yaml; //导入依赖的package包/类
/**
* Test that the parser can load formatted dates when embedded in JavaBeans
*
* @author Steve Leach
*/
public void testDatesInBeans() {
YamlConfig.getDefaultConfig().setDateFormat(DateWrapper.DATEFORMAT_YAML);
Date d1 = TestDateTimeParser.getDate( 1965, 10, 01, 0, 0, 0 );
Person bob = new Person();
bob.setName("Bob");
bob.setBirthDate(d1);
Company anyCorp = new Company();
anyCorp.setName("AnyCorp");
anyCorp.setPresident(bob);
String s = Yaml.dump(anyCorp,true);
Company company = Yaml.loadType( s, Company.class );
Person president = company.getPresident();
assertEquals( bob.getBirthDate(), president.getBirthDate(), TestDateTimeParser.DELTA_30SEC );
YamlConfig.getDefaultConfig().setDateFormat(null);
}
示例11: testSequenceMapBug2
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testSequenceMapBug2(){
String s = "players:\n"+
" -\n"+
" name: Mark McGwire\n"+
" hr: 65\n"+
" avg: 0.278\n"+
" -\n"+
" name: Sammy Sosa\n"+
" hr: 63\n"+
" avg: 0.288\n";
Map m = (Map)Yaml.load(s);
System.out.println(m);
List players = (List)m.get("players");
assertEquals(2, players.size());
Map mm = (Map)players.get(0);
assertEquals("Mark McGwire", mm.get("name"));
Map ss = (Map)players.get(1);
assertEquals("Sammy Sosa", ss.get("name"));
}
示例12: testThreeSlashesAtTheEnd
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testThreeSlashesAtTheEnd(){
final String slashes="ghghghg hj hkl; \\\\\\";
Map amap=new HashMap();
amap.put("key", slashes);
String dump = Yaml.dump(amap);
System.out.println(dump);
Object o = Yaml.load(dump);
System.out.println(o);
integrationTest(amap, "testThreeSlashesAtTheEnd", new Validator<Map>(){
public void validate(Map m){
assertEquals(slashes, m.get("key"));
}
});
}
示例13: testOrdering
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testOrdering(){
Person p = new Person();
p.setName("kevin");
p.setAge(4);
p.setSalary(34859.0);
p.setNetWorth(new BigDecimal("1000000.00"));
System.out.println(Yaml.dump(p, true));
String expected =
"--- \r\n" +
"age: 4\r\n" +
"name: kevin\r\n" +
"netWorth: 1000000.00\r\n" +
"salary: 34859.0\r\n";
assertEquals(expected, Yaml.dump(p, true));
}
示例14: testCanonicalGraph
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testCanonicalGraph(){
Person p = new Person();
p.setName("Bill");
Person spouse = new Person();
spouse.setName("Hillary");
p.setSpouse(spouse);
spouse.setSpouse(p);
List l = new ArrayList();
l.add(p);
l.add(spouse);
System.out.println(Yaml.dump(l));
String expected = "--- \r\n" +
"- &1 !org.ho.yaml.tests.Person\r\n" +
" name: Bill\r\n" +
" spouse: &2 !org.ho.yaml.tests.Person\r\n" +
" name: Hillary\r\n" +
" spouse: *1\r\n" +
"- *2\r\n";
assertEquals(expected, Yaml.dump(l));
}
示例15: load
import org.ho.yaml.Yaml; //导入依赖的package包/类
/**
* 读取配置文件
* <br><i>at 2014年7月12日下午4:36:36</i>
* @author lichee
* @see <a href="http://nicecoder.net">nicecoder.net</a>
* @param path
*/
@SuppressWarnings("unchecked")
public void load(String path){
try {
File config = new File(path);
meta = (Map<String, String>) Yaml.load(config);
setMeta(meta);
setAuthor(meta.get("author"));
setName(meta.get("name"));
setVersion(meta.get("version"));
//路径设置
absRootDir = PathUtil.subFileName(config.getAbsolutePath());
postsDir = absRootDir+postsDir;
outputDir = absRootDir+outputDir;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}