"Agile Pair Coding" Data Type Mapping

Source: Internet
Author: User

Introduced

This afternoon spent about 1 hours, and colleagues agile Pair coding Agile developed a, feel very cool.

The direct benefits of Agile Pair coding are that they don't waste time and are efficient; idea quickly reached a consensus, not obsessed with pointless discussion; idea flew coding, not addicted to brainstorming, code more rigorous, refactoring probabilities, deepening the basic feeling, learning from each other, appreciating each other, Avoid ignorance and avoid feeling good about yourself ...

The main implementation of the code: from all types of files, get all NE types under the All Object Types under the All Properties of the Data Type .

Of course, this article is only a short period of draft version, there may be some problems, please correct me.


Package shuai.study.spring.validator;/** * @ClassName: Service * @Description: TODO * @author Zhou Shengshuai * @date 2014 Year August 8 pm 3:40:45 *  */public interface Service {public void Initialize ();p ublic void Destroy ();}

package  shuai.study.spring.validator;/** * @ClassName: Typemapper * @Description: TODO * @author Zhou Shengshuai * @date August 8, 2014 PM 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 August 8, 2014 PM 3 : 10:06 * */public class Datatypemapper implements Typemapper, Service {private String FilePath = Null;private Map<stri Ng, Map<string, map<string, string>>> allnetypemap = Null;public datatypemapper () {}public void SetFilePath (String filePath) {this.filepath = FilePath;} @Overridepublic void Initialize () {Allnetypemap = Getallnetypemap (FilePath);} @Overridepublic void Destroy () {allnetypemap.clear (); allnetypemap = null;} @Overridepublic string GetType (String Netype, String ObjectType, String fieldName) {if (Allnetypemap! = null && AL Lnetypemap.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! = Nu ll && 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 = Reade R.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 && Amp 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 August 8, 2014 PM 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 ();}}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.