当前位置: 首页>>代码示例>>Java>>正文


Java Yaml.loadType方法代码示例

本文整理汇总了Java中org.ho.yaml.Yaml.loadType方法的典型用法代码示例。如果您正苦于以下问题:Java Yaml.loadType方法的具体用法?Java Yaml.loadType怎么用?Java Yaml.loadType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ho.yaml.Yaml的用法示例。


在下文中一共展示了Yaml.loadType方法的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;
}
 
开发者ID:imotSpot,项目名称:imotSpot,代码行数:25,代码来源:Configuration.java

示例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;
}
 
开发者ID:knshen,项目名称:JSearcher,代码行数:18,代码来源:YamlHandler.java

示例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());
    
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:21,代码来源:IntegrationTests.java

示例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());
    
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:21,代码来源:IntegrationTests.java

示例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);
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:23,代码来源:IntegrationTests.java

示例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);    	
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:23,代码来源:IntegrationTests.java

示例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);
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:19,代码来源:IntegrationTests.java

示例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) {
        
    }
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:19,代码来源:IntegrationTests.java

示例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 );
    }
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:24,代码来源:IntegrationTests.java

示例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);
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:27,代码来源:IntegrationTests.java

示例11: loadYamlToHashMap

import org.ho.yaml.Yaml; //导入方法依赖的package包/类
private static HashMap loadYamlToHashMap(String filePath) {
	HashMap hashmap = null; 
	File f = new File(filePath);
	try {
		hashmap = Yaml.loadType(new FileInputStream(f.getAbsolutePath()), HashMap.class);
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}
	return hashmap;
}
 
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:11,代码来源:TomcatConfigReadin.java

示例12: loadFileToHashMap

import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public HashMap loadFileToHashMap(String filePath) {
	HashMap hashmap = null; 
	File f = new File(filePath);
	try {
		hashmap = Yaml.loadType(new FileInputStream(f.getAbsolutePath()), HashMap.class);
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}
	return hashmap;
}
 
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:11,代码来源:HadoopConfigReadin.java

示例13: getStorageConfig

import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public static Map<String, Object> getStorageConfig(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 && !entry.getKey().equals("cluster")) {
				Map<String, Object> paras = (HashMap<String, Object>)entry.getValue();
				res.put("host", paras.get("host"));
				res.put("port", paras.get("port"));
				
				if(entry.getKey().equals("mysql")) {
					res.put("db", paras.get("db"));
					res.put("user", paras.get("user"));
					res.put("password", paras.get("password"));
				}
				else if(entry.getKey().equals("mongodb")) {
					res.put("db", paras.get("db"));
				}
				else if(entry.getKey().equals("es")) {
					res.put("cluster_name", paras.get("cluster_name"));
				}
			}
		}
		
	} catch(FileNotFoundException fe) {
		fe.printStackTrace();
	}
	return res;
}
 
开发者ID:knshen,项目名称:JSearcher,代码行数:31,代码来源:YamlHandler.java

示例14: getYamlFile

import org.ho.yaml.Yaml; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void getYamlFile() {
	System.out.println("locator->getYamlFile:-----" + yamlfile);
	File f = new File("locator/" + yamlfile + ".yaml");
	try {
		ml = Yaml.loadType(new FileInputStream(f.getAbsolutePath()),
				HashMap.class);
		// HashMap ml = Yaml.loadType(
		// new FileInputStream(f.getAbsolutePath()), HashMap.class);
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:yajing-zh,项目名称:learn_selenium2,代码行数:15,代码来源:Locator.java

示例15: testDateBug

import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testDateBug(){
    String s = "---\n" + 
                "var: !java.util.Date 16200000";
    Map map = Yaml.loadType(s, HashMap.class);
    assertEquals(Date.class, map.get("var").getClass());
    assertEquals(16200000, ((Date)map.get("var")).getTime());
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:8,代码来源:IntegrationTests.java


注:本文中的org.ho.yaml.Yaml.loadType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。