1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SQLの変数チェック

Posted at
VarCheck.java
package varCheck;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public class VarCheck {
	private List<String> listKey =new ArrayList<String>();
	private List<String> data=new ArrayList<String>();
	private List<String> listVar=new ArrayList<String>();
	private Set<String> set1=new TreeSet<String>();
	private Set<String> set2=new TreeSet<String>();
	
	public VarCheck() throws IOException {
		
		initListKeyValue();
		
		File file = new File("input.txt");//プロジェクトフォルダの直下
		BufferedReader br=new BufferedReader(new FileReader(file));
		
		//一旦Stringの配列に入れる
		String line0="";
		while ((line0 = br.readLine()) != null) {
			data.add(line0);
		}
		br.close();
		
		int flg=1;
		for(int i=0; i<data.size();i++) {
			//先頭からSETの文字を検索し、途切れたら"---SET 終了---"を出力
			String s =data.get(i);
			if(flg==1 && s.indexOf("SET")==-1) {
				flg=0;
				data.set(i, "---@SET 終了---");
				break;
			}
		}
		
		//debug用に一度すべて出力
//		for(int i=0; i<data.size();i++) {
//			System.out.println(data.get(i));
//		}
//		System.out.println("-----");
		
		boolean firstFlg=true;
		for(int i=0; i<data.size();i++) {
			String line =data.get(i);
			if(line.contains("---@SET 終了---")) {
				firstFlg=false;
//				System.out.println("aaa:" + line);
				
			} else if(line.contains("@")) {
				int a=line.indexOf("@");
				int b=line.indexOf(":");
				
				String s ="";
				if(b == -1) {
					s =line.substring(a);
					//チェック配列に追加
					listVar.add(s);
				} else {
					try {
						s=line.substring(a,b);
					}catch(Exception e) {
						System.out.printf("line=%s\n", line);
						System.out.printf("%s,%s\n", a,b);
						throw e;
					}
				}
//				System.out.println("bbb:" + s);
				//------------
//				String sp[] = s.split("@");
//				for(String s0 : sp) {
//					System.out.println("\tccc:[" + s0+"]");
//				}
//				System.out.println("\tsubstrin0:[" + s +"]");

				//------------------------------------------------------------------------
				//inputは文字列。outputはListに格納する。

				
				if(firstFlg) {
					set1.add(s.trim());
				} else {
					List<String> list = StringSpritToList(s);
					for(String s4:list) {
						set2.add(s4);
					}
				}
			}
		}
		System.out.println("=====結果=====");
		System.out.printf("set1 size=%s\n", set1.size()); 
		System.out.printf("set2 size=%s\n", set2.size());
		System.out.print("set1 toArray="); 
		for(String s : set1) {
			System.out.printf("[%s] ", s);
		}
		System.out.println(); 

		System.out.print("set2 toArray=");
		for(String s : set2) {
			System.out.printf("[%s] ", s);
		}
		System.out.println();
	}
	
	private static List<String> StringSpritToList(String s) {
		
		List<String> list = new ArrayList<String>();
		int sindex = s.indexOf("@");//
		String s2 = "";
		while(sindex != -1) {
			s2 = s.substring(sindex);
//			System.out.println("\tsubstring:[" + s2 +"]");
			s2 = s2.split(" ")[0];
//			System.out.println("\t\tsubstring:[" + s2 +"]");
//			System.out.println("\ta1:[" + sindex +"]");
			sindex = s.indexOf("@",sindex + 1);
			list.add(s2);
		}
		//------------------------------------------------------------------------
//		for(String s3 : list) {
////			System.out.printf("list=%s\n", s3);
//		}
		//------------------------------------------------------------------------
		return list;
	}

	private void initListKeyValue() {
		listKey.add("@");
	}

	public static void main(String[] args) throws Exception {
		new VarCheck();
	}
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?