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


相关文章
|
安全 Java API
Java中的Servlet编程详解
Java中的Servlet编程详解
|
20小时前
|
数据采集 人工智能 安全
|
10天前
|
云安全 监控 安全
|
1天前
|
自然语言处理 API
万相 Wan2.6 全新升级发布!人人都能当导演的时代来了
通义万相2.6全新升级,支持文生图、图生视频、文生视频,打造电影级创作体验。智能分镜、角色扮演、音画同步,让创意一键成片,大众也能轻松制作高质量短视频。
822 150
|
15天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
1587 8
|
6天前
|
人工智能 前端开发 文件存储
星哥带你玩飞牛NAS-12:开源笔记的进化之路,效率玩家的新选择
星哥带你玩转飞牛NAS,部署开源笔记TriliumNext!支持树状知识库、多端同步、AI摘要与代码高亮,数据自主可控,打造个人“第二大脑”。高效玩家的新选择,轻松搭建专属知识管理体系。
353 152
|
6天前
|
人工智能 自然语言处理 API
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸
一句话生成拓扑图!next-ai-draw-io 结合 AI 与 Draw.io,通过自然语言秒出架构图,支持私有部署、免费大模型接口,彻底解放生产力,绘图效率直接爆炸。
544 152
|
8天前
|
人工智能 安全 前端开发
AgentScope Java v1.0 发布,让 Java 开发者轻松构建企业级 Agentic 应用
AgentScope 重磅发布 Java 版本,拥抱企业开发主流技术栈。
527 14
|
1天前
|
编解码 人工智能 机器人
通义万相2.6,模型使用指南
智能分镜 | 多镜头叙事 | 支持15秒视频生成 | 高品质声音生成 | 多人稳定对话