189 8069 5689

javajson代码自动生成-创新互联

package code;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;

public class Code {

   private static List readFile(String filename)
   {
      List fileline = new ArrayList();

      try {

         FileReader in = new FileReader(filename);
         LineNumberReader reader = new LineNumberReader(in);

         String s = reader.readLine();
         while( s != null )
         {
            if(!s.startsWith("#"))
            {
               fileline.add(s);
            }
            s = reader.readLine();
         }

         reader.close();
         in.close();
      }catch(Exception e)
      {
         e.printStackTrace();
      }

      return fileline;
   }

   public static void genarateCode(List line)
   {
      String cr=" ";

      try{

         FileWriter fw = new FileWriter("class.java");
           for(int i = 0;i < line.size();i++)
         {
            String [] data = line.get(i).split(",");
            if(data[1].trim().equalsIgnoreCase("int"))
            {
              fw.write("@SerializedName(""+data[0]+"")"+cr);
              fw.write("private Integer "+toLowerCaseFirst(data[0])+";"+cr);
            }
            else if(data[1].trim().equalsIgnoreCase("string"))
            {
               fw.write("@SerializedName(""+data[0]+"")"+cr);
               fw.write("private String "+toLowerCaseFirst(data[0])+";"+cr);
            }
         }

           fw.write(cr);
           fw.write(cr);

           for(int i = 0;i < line.size();i++)
          {
             String [] data = line.get(i).split(",");
             if(data[1].trim().equalsIgnoreCase("int"))
             {
                fw.write("public void set"+data[0]+"(Integer value)"+cr);
                fw.write("{"+cr);
                fw.write("   "+toLowerCaseFirst(data[0])+"="+"value;"+cr);
                fw.write("}"+cr);

                fw.write("public Integer get"+data[0]+"()"+cr);
                fw.write("{"+cr);
                fw.write("   return "+toLowerCaseFirst(data[0])+";"+cr);
                fw.write("}"+cr);
             }
             else if(data[1].trim().equalsIgnoreCase("string"))
             {
                fw.write("public void set"+data[0]+"(String value)"+cr);
              fw.write("{"+cr);
              fw.write("   "+toLowerCaseFirst(data[0])+"="+"value;"+cr);
              fw.write("}"+cr);

              fw.write("public String get"+data[0]+"()"+cr);
              fw.write("{"+cr);
              fw.write("   return "+toLowerCaseFirst(data[0])+";"+cr);
              fw.write("}"+cr);
             }
          }

           fw.close();
      }catch(Exception e)
      {

      }
   }

   public static String toLowerCaseFirst(String str)
   {
      StringBuilder sb = new StringBuilder(str);
      sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
      str = sb.toString();
      return str;
   }

   public static void main(String args[])
   {

      List fileline = readFile("field.txt");

        genarateCode(fileline);
        System.out.println("success!");

   }

}

10年积累的网站建设、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有兰州免费网站建设让你可以放心的选择与我们合作。field.txtjavajson代码自动生成

Name,String
Url,String
Duration,String
Desc,String


当前标题:javajson代码自动生成-创新互联
网站URL:http://cdxtjz.cn/article/dgssji.html

其他资讯