⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 input.java

📁 一个java编写的DFA(difinite automata reader) 拥有完备的图形界面和rebustness 另付.dat的测试文件
💻 JAVA
字号:
package automation;

import java.io.*;
import java.util.StringTokenizer;
import javax.swing.JFileChooser;


public class Input 
{

	private int count;
	private int state;
	
	private String readS = "";
	private String line = "";
	private File read;
	
	private BufferedReader br;
	private BufferedReader testBR;
	private FileReader fr;
	private FileReader fr2;
	private Automation automation;
	private Transition transitions[];
	
	private int finals[];
	private String[] figure;
	
	public Input()
	{
		
	}
	
	public int execute()
	{
			JFileChooser jfc = new JFileChooser();
			jfc.setCurrentDirectory(new File("."));
			jfc.setAcceptAllFileFilterUsed(false);
			jfc.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() 
			{
				public boolean accept(File f)
				{
					if (f.getName().endsWith("dat"))
						return true;
					else
						return false;
				}
				public String getDescription() 
				{
					return "(*.dat)";
				}
			}
			);
			jfc.showSaveDialog(null);	
			
		readS = jfc.getSelectedFile().getPath();
		read = new File(readS);
		try 
		{
			fr = new FileReader(read);
			fr2 = new FileReader(read);
			br = new BufferedReader(fr);
			testBR = new BufferedReader(fr2);
		} 
		catch (FileNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try 
		{
			count = 0;
			/*
			 *  the dat file must at least containe
			 *  number of states
			 *  final states (separated by blanks)
			 *  symbols in alphabet (not separated)
			 *  transitions in fJ in the form state-state-symbol (one per line)
			 *  at least four lines
			 */		
			while((line = testBR.readLine()) != null)
			{
				count++;
			}
			if(count <= 3)
			{
				return -1;
			}
			else
			{
				count -= 3;//Let count be transitions numbers
			}
			
			/*
			 * Start Generating Automation
			 */
			
			transitions = new Transition[count];
			/*
			for(int i = 0; i < count; i++)
			{
				transitions[i] = new Transition();
			}
			*/
			if((line = br.readLine()) == null)
			{
				return -1;
			}
			else
			{
				state = Integer.parseInt(line);
				if((line = br.readLine()) == null)
				{
					return -1;
				}
				else
				{
					StringTokenizer st = new StringTokenizer(line," ");
					int t = st.countTokens();
					finals = new int[t];
					for(int i = 0; i < t; i++)
					{
						finals[i] = Integer.parseInt(st.nextToken());
					}
				}
				if((line = br.readLine()) == null)
				{
					return -1;
				}
				else
				{
					int tempi = line.length();
					figure = new String[tempi];
					for(int i = 0; i < tempi; i++)
					{
						figure[i] = String.valueOf(line.charAt(i));
					}
					int tempint = 0;
					while ((line = br.readLine()) != null)
					{
						StringTokenizer st = new StringTokenizer(line,"-");
						if(st.countTokens() != 3)
						{
							return -1;
						}
						else
						{
							transitions[tempint] = new Transition
								(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), st.nextToken());
						}
						tempint++;
					}
				}
			}
			
			automation = new Automation(state, count, finals, figure, transitions);
		} 
		catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
	

	public String getReads()
	{
		return this.readS;
	}
	
	public Automation getAutomation()
	{
		return this.automation;
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -