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

📄 defaultchecker.java

📁 网络分析软件pajek的数据格式转换工具。
💻 JAVA
字号:
//Skye Bender-deMoll draft translation code 2/13/01
//skyebend@bennington.edu

package PajekConverter;

import java.text.*;
import java.util.*;

/*
Default checker takes strings and attempts to parse them into the appropriate data structure
returns errors, stores data internaly in a DefaultDataEntry Object.

When asked to return nodes, it asks the data entry object to assemble network structure, tracks number and appropriateness
of catagory and numeric variables, and returns a list of nodes which can be used for output

DATA CHECKER COULD CHECK # OF COLOR CLASSES AND SETUP LOOKUP TABLES!..
*/

public class DefaultChecker extends Object
{
	//globals
	private int numRows;
	private DefaultDataEntry data;
	private int currentRow;
	private boolean rowIsError = false;
	private boolean rowIsForOutput = true;
	private String rowParseErrors = "";


	//instantiates DefaultChecker with rows number of rows
	public DefaultChecker(int rows)
	{
		numRows = rows;
		data = new DefaultDataEntry(rows);
	}

//------Methods---------

//parse attempts to parse each string to its appropriate catagory, returns error messages
//and sends parsed values to DefaultDataEntry

	public String parseRow(int row, String rawId, String rawLinkId, String rawLabel,
							String rawShape, String rawSize,String rawColor, String rawX,
							String rawY ,String rawArcColor, String rawArcWidth, String rawArcWeight)
	{
		//reset control vars
		currentRow = row;
		rowIsError = false;
		rowIsForOutput = true;
		rowParseErrors = "";

		//remove extra whitespace from strings
		rawId = rawId.trim();
		rawLinkId = rawLinkId.trim();
		rawLabel = rawLabel.trim();
		rawShape = rawShape.trim();
		rawColor = rawColor.trim();
		rawArcColor = rawArcColor.trim();

		//try parsing vars
		double size = toDouble(rawSize);
		double xCoord = toDouble(rawX);
		double yCoord = toDouble(rawY);
		double arcWidth = toDouble(rawArcWidth);
		double arcWeight = toDouble(rawArcWeight);

		//CHECK THAT ID != "-"


		//send to DefaultDataEntry
		data.addEntry(rawId, rawLinkId, rawLabel, rawShape, size, rawColor, xCoord, yCoord, rawArcColor, arcWidth, arcWeight, rowIsForOutput,
						rowIsError, rowParseErrors);

		if (rowIsError)
		{
			rowParseErrors = "ERROR Row "+currentRow+":"+rowParseErrors+"\n";
		}
		return rowParseErrors;

	}



//-----------Accesors-------------------
// some set commands may parse their input
// or check ranges

//getData returns the DefualtDataEntry object
	public DefaultDataEntry getData()
	{
		return data;
	}

//getRow returns a string representing the parsed values of the line from the DefualtData Entry
	public String getRow(int index)
	{
		return data.getRow(index);
	}



//-----------Utility Methods ----------



	//TO INT   takes text from passed string and parses it to return an int
	//returns -1 if unable to parse
	 public int toInt(String str)
	 {
		int returnInt = -1;
		str.trim();
		if (!(str.equals("_")))
		{
			try
			{
				returnInt = new DecimalFormat().parse(str).intValue();
			}
			catch(ParseException e)
			{
				rowIsError = true;
				rowParseErrors = rowParseErrors +"\tIntegerParsingError:"+ e.getMessage()+"\n";
			}
		}
		return returnInt;
     }

	//TO DOUBLE   takes text from passed string and parses it to return a double
	// returns  1.000 if an exception is thrown
	public double toDouble(String str)
	{
		double returnDouble = 1.000;
		str.trim();
		if (!str.equals("_"))
		{
			if (!str.equals("default"))
			{
				try
				{
					returnDouble = new DecimalFormat().parse(str).doubleValue();
				}
				catch(ParseException e)
				{
					rowIsError = true;
					rowParseErrors = rowParseErrors +"\tDoubleParsingError:"+ e.getMessage()+"\n";
				}
			}
		}
		return returnDouble;
	}

	//DOUBLE TO STRING takes a double and returns a formated string
	public String doubleToString(double dbl){
			NumberFormat returnFormat = NumberFormat.getNumberInstance();
			returnFormat.setMinimumFractionDigits(3);
			returnFormat.setMaximumFractionDigits(3);
			returnFormat.setGroupingUsed(false); //so it won't spit out commas
			String returnString = returnFormat.format(dbl);
			return returnString;
	}


}

⌨️ 快捷键说明

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