【Agile Pair Coding】Data Type Mapping

简介: <p><span style="font-family:KaiTi_GB2312; font-size:14px">介绍</span></p> <p><span style="font-family:KaiTi_GB2312; font-size:14px">    今天下午用了1个小时左右,和同事Agile Pair Coding敏捷开发了一把,感觉挺爽的。</span></p> <

介绍

    今天下午用了1个小时左右,和同事Agile Pair Coding敏捷开发了一把,感觉挺爽的。

    Agile Pair Coding给我们带来的直接好处是:相互不浪费时间(就两个人),高效;idea很快达成共识(就两个人),不纠结于无谓的讨论;idea立马coding,不沉迷于头脑风暴;代码更严谨;重构概率大;加深基情;相互学习,相互欣赏,相互指正;避免无知,避免自我感觉良好......

    代码主要实现:从所有类型文件中,得到所有NE类型下的所有Object类型下的所有属性数据类型

    当然,本文只是一个短时间内的Draft版本,可能会有一些问题,敬请指正。


package shuai.study.spring.validator;

/**
 * @ClassName: Service
 * @Description: TODO
 * @author Zhou Shengshuai
 * @date 2014年8月8日 下午3:40:45
 * 
 */
public interface Service {

	public void initialize();

	public void destroy();
}

package shuai.study.spring.validator;

/**
 * @ClassName: TypeMapper
 * @Description: TODO
 * @author Zhou Shengshuai
 * @date 2014年8月8日 下午3:40:26
 * 
 */
public interface TypeMapper {

	public String getType(String neType, String objectType, String fieldName);

}
package shuai.study.spring.validator;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: FileTypeMapper
 * @Description: TODO
 * @author Zhou Shengshuai
 * @date 2014年8月8日 下午3:10:06
 * 
 */
public class DataTypeMapper implements TypeMapper, Service {
	private String filePath = null;
	private Map<String, Map<String, Map<String, String>>> allNeTypeMap = null;

	public DataTypeMapper() {
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	@Override
	public void initialize() {
		allNeTypeMap = getAllNeTypeMap(filePath);
	}

	@Override
	public void destroy() {
		allNeTypeMap.clear();
		allNeTypeMap = null;
	}

	@Override
	public String getType(String neType, String objectType, String fieldName) {
		if (allNeTypeMap != null && allNeTypeMap.containsKey(neType)) {
			Map<String, Map<String, String>> neTypeMap = allNeTypeMap.get(neType);

			if (neTypeMap != null && neTypeMap.containsKey(objectType)) {
				Map<String, String> objectTypeMap = neTypeMap.get(objectType);

				if (objectTypeMap != null && objectTypeMap.containsKey(fieldName)) {
					return objectTypeMap.get(fieldName);
				}
			}
		}

		return null;
	}

	private static Map<String, Map<String, Map<String, String>>> getAllNeTypeMap(String filepath) {
		Map<String, Map<String, Map<String, String>>> allNeTypeMap = new HashMap<String, Map<String, Map<String, String>>>();

		File[] files = new File(filepath).listFiles();

		for (File file : files) {
			String filename = file.getName();
			if (filename != null && filename.matches("\\w+-.*")) {
				allNeTypeMap.put(filename.split("-")[0], getNeTypeMap(file));
			}
		}

		return allNeTypeMap;
	}

	private static Map<String, Map<String, String>> getNeTypeMap(File file) {
		Map<String, Map<String, String>> neTypeMap = new HashMap<String, Map<String, String>>();

		BufferedReader reader = null;
		String line = null;
		Map<String, String> objectTypeMap = null;

		try {
			reader = new BufferedReader(new FileReader(file));

			while ((line = reader.readLine()) != null) {
				if (line.matches("\\[\\w+\\]")) {
					String objectType = line.substring(1, line.length() - 1).trim();

					if (!neTypeMap.containsKey(objectType)) {
						neTypeMap.put(objectType, new HashMap<String, String>());
					}

					objectTypeMap = neTypeMap.get(objectType);
				} else if (line.matches("\\b*\\w+\\b*:\\b*\\w+\\b*")) {
					String[] array = line.split(":");

					if (objectTypeMap != null && array != null && array.length == 2) {
						objectTypeMap.put(array[0].trim(), array[1].trim());
					}
				}
			}
		} catch (FileNotFoundException fnfe) {
			fnfe.printStackTrace();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		} finally {
			try {
				reader.close();
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}
		}

		return neTypeMap;
	}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

	<bean id="TypeMapper" class="shuai.study.spring.validator.DataTypeMapper" init-method="initialize" destroy-method="destroy" scope="singleton">
		<property name="filePath" value="D:/userdata/shengshu/Desktop/validation" />
	</bean>

</beans>
 
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
 * @ClassName: Test
 * @Description: TODO
 * @author Zhou Shengshuai
 * @date 2014年8月8日 下午3:52:55
 * 
 */
public class MapperApp {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("spring-context-mapper.xml");

		TypeMapper mapper = (DataTypeMapper) context.getBean("TypeMapper");

		System.out.println(mapper.getType("CSCF", "PcscfFunction", "MaxBHSA"));

		context.getBeanFactory().destroySingletons();
	}
}


相关文章
|
7月前
Transparent Data Encryption Data Dynamic and Data Dictionary Views You can query a set of dynamic and data dictionary views to find more information about Transparent Data Encryption (TDE) data.
Transparent Data Encryption Data Dynamic and Data Dictionary Views You can query a set of dynamic and data dictionary views to find more information about Transparent Data Encryption (TDE) data.
54 2
|
3月前
|
Go 索引
internal\model\data_support.go:17:10: cannot use _ as value or type
internal\model\data_support.go:17:10: cannot use _ as value or type
|
4月前
|
Python
【Python】解决Can‘t find model ‘en‘. It doesn‘t seem to be a shortcut link, a Python package or a valid
在使用以下代码时,报错Can’t find model ‘en’. It doesn’t seem to be a shortcut link, a Python package or a valid path to a data directory.
62 1
|
5月前
|
XML 数据格式 Python
【Python】已解决:xml.parsers.expat.ExpatError: no element found: Line 1, column 0
【Python】已解决:xml.parsers.expat.ExpatError: no element found: Line 1, column 0
129 0
|
Java 数据库连接 mybatis
mybatis关于出现Parameter ‘XXX‘ not found. Available parameters are [collection, list]问题的解决方案
mybatis关于出现Parameter ‘XXX‘ not found. Available parameters are [collection, list]问题的解决方案
1144 0
使用pageHelper报错 Type definition error: [simple type, classXXXX]
使用pageHelper报错 Type definition error: [simple type, classXXXX]
|
编解码 搜索推荐 算法
Data-Data Objects and Attribute Types| 学习笔记
快速学习 Data-Data Objects and Attribute Types。
Data-Data Objects and Attribute Types| 学习笔记
|
Java
java实战小结-Controller报错:Content type ‘multipart/form-data;boundary=----WebKitFormBoundaryxxxx not supp
java实战小结-Controller报错:Content type ‘multipart/form-data;boundary=----WebKitFormBoundaryxxxx not supp
422 0
|
算法
On the Correct and Complete Enumeration of the Core Search Space
在之前的文章中我们讨论了基于graph的DP-based算法,来解决join ordering的枚举问题。 这些DP算法通过join predicate描述的连通性,解决了枚举可能的表组合问题,但join graph本身(即使hypergraph)是无法完整的描述join语义的,因为连通边本身无法描述不同类型的join语义,例如left outer join/semi join/anti join...,因此即使找到了所谓的csg-cmp-pair,也不一定是有效的plan。 这篇paper讨论的就是这个问题,当枚举出一个csg-cmp-pair (S1 o S2),如何判断这是有效的join
448 0
On the Correct and Complete Enumeration of the Core Search Space