【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();
	}
}


相关文章
|
29天前
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.
11 2
|
4月前
|
Scala
【已解决】Specifying keys via field positions is only valid for tuple data types. Type: GenericType<scala
【已解决】Specifying keys via field positions is only valid for tuple data types. Type: GenericType<scala
22 0
使用pageHelper报错 Type definition error: [simple type, classXXXX]
使用pageHelper报错 Type definition error: [simple type, classXXXX]
|
9月前
|
JSON 数据格式
UE4 structure and JSON conversion - DTBPJson plugin description
UE4 structure and JSON conversion - DTBPJson plugin description
57 0
|
编解码 搜索推荐 算法
Data-Data Objects and Attribute Types| 学习笔记
快速学习 Data-Data Objects and Attribute Types。
131 0
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
303 0
How to put S4 extension field to CRM WebUI search view in the design time
How to put S4 extension field to CRM WebUI search view in the design time
How to put S4 extension field to CRM WebUI search view in the design time
|
Java
Hybris DDIC type and its counterpart model class
Hybris DDIC type and its counterpart model class
110 0
Hybris DDIC type and its counterpart model class
Cannot find source code based button in SE24
When you are logging on to customer system for incident handling, you want to switch to source code to perform some keyword search. However, you could not find button “Source code based builder” in toolbar, with following warning message: ———————————————— 版权声明:本文为CSDN博主「汪子熙」的原创文章,遵循CC 4.0 BY-SA版权协
Cannot find source code based button in SE24