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

📄 misc.java

📁 一个开源的基于java开发的数据库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package sql4j.util;

/**
 * Insert the type's description here.
 * Creation date: (10/20/00 4:06:35 AM)
 * @author: Jianguo Lu
 */
 
import org.w3c.dom.*;
import java.util.*;
import java.io.*;
import javax.swing.*;

public class Misc{
				
			  					  /**
 * Misc constructor comment.
 */
public Misc() {
	super();
}
  /**
   ** Method : addIneqs (String)
   ** Purpose: Replaces '&lt;' with '<' , and '&gt;' with '>' in a String.
   **          Required for conditions in templates to parse properly.
   **/
  public static String addIneqs(String s){
	String result = replaceStr(s, "&lt;", "<");
	return replaceStr(result, "&gt;", ">");
  }            
  /**
   * Removes characters from xml document that are known to cause parsing errors
   */
  public static String cleanXML(String xml) {
	String result = xml;
	//result = result.replace('?, '*');
	return result;
  }            
  /**
   ** Method : compress (String[])
   ** Purpose: Removes all null Strings from the input String array, and returns the result.
   **/
  public static String[] compress(String[] a){
	int leng = a.length;
	int nullCount=0;
	for (int i =0; i<leng; i++){
	  if (a[i]==null) nullCount++;
	}
	String[] result = new String[leng-nullCount];
	int count = 0;
	for (int i = 0; i<leng; i++){
	  if (a[i]!=null){
	result[count]=a[i];
	count++;
	  }
	}
	return result;
  }            
  /**
   ** Method : compressEmpty (String[])
   ** Purpose: Removes all empty Strings from the input String array, and returns the result.
   **/
  public static String[] compressEmpty(String[] a){
	Vector resultV = new Vector();
	for (int i=0; i<a.length; i++)
	  if (!a[i].equals(""))
		resultV.addElement(a[i]);
	String[] result = new String[resultV.size()];
	resultV.copyInto(result);
	return result;
  }            
  /**
   ** Method : concat (String[], String[])
   ** Purpose: Concatenates two String arrays into a larger array, all elements preserved
   **/
  public static String[] concat(String[] str1, String[] str2) {
	int len1 = str1.length;
	int len2 = str2.length;
	String[] combined = new String[len1 + len2];
	for (int i=0; i<len1; i++)
	  combined[i]=str1[i];
	for (int i=0; i<len2; i++)
	  combined[len1+i]=str2[i];
	return combined;
  }            
/**
 * Insert the method's description here.
 * Creation date: (1/17/01 3:29:22 PM)
 * @return boolean
 * @param v java.util.Vector
 * @param s java.lang.String
 */
public static boolean contains(Vector v, String s) {
	for (Enumeration e = v.elements(); e.hasMoreElements();) {
		if (s.equals((String) e.nextElement()))
			return true;
	}
	return false;
}/**
 * get the last token of the dotted name.
 * Creation date: (1/11/01 10:49:44 AM)
 * @return java.lang.String
 * @param dottedName java.lang.String
 */      
  public static void debugMessage(Object s){

	// if(XIBData.DEBUG) JOptionPane.showMessageDialog(null,s);
	if (s instanceof String)
	  System.out.println((String)s);
  }            
  /** change <XMP> "&quot;" </XMP> to <CODE> "\""</CODE>, etc.
   **/
  public static String deNormalize(String s){
	String str = "";
	int len = (s!=null)?s.length():0;
	for(int i=0; i<len; i++){
	  char ch = s.charAt(i);
	  if (ch == '&'){
	    if (s.charAt(i+1)=='q' && 
	        s.charAt(i+2)=='u' && 
	        s.charAt(i+3)=='o' &&
	        s.charAt(i+4)=='t' && 
	        s.charAt(i+5)==';' ){
	      str+="\"";
	      i=i+5;
	    } else {
	} 
	  }
	  str+=ch;
	}
	return str;
  }            
  /** Write error messages to the errlog file.
   */
  public static void errlog(String s){
	try{
	  File outfile;
	  outfile = new File("errlog");
	  FileOutputStream fout;
	  fout = new FileOutputStream(outfile);
	  BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fout));     
	  bw.write(s);
	  bw.write("/n/n");
	  bw.close();
	  fout.close();
	}catch (Exception e){e.printStackTrace();
	}
  }            
  public static String file2string(File file){	
	String result="";
	try{
	  FileInputStream fin = new FileInputStream(file);
	  BufferedReader br = new BufferedReader(new InputStreamReader(fin));
	  String thisLine;
	  while ((thisLine = br.readLine())!=null) {
	result=result+thisLine+"\n";
	  }
	  fin.close();
	}catch (Exception e){
	  e.printStackTrace();
	}
	return result;
  }            
  /** read a file into a string.
   **/
  public static String file2string(String fileName){ 
	String result="";
	try{
	  File myfile;
	  FileInputStream fin;
	  
	  myfile=new File(fileName);
	  fin = new FileInputStream(myfile);
	  BufferedReader br = new BufferedReader(new InputStreamReader(fin));
	  String thisLine;
	  while ((thisLine = br.readLine())!=null) {
	    result=result+thisLine+"\n";
	  }
	  fin.close();
	}catch (Exception e){
	  Misc.message("fail to read a file in file2string. File name is "+fileName);
	  e.printStackTrace();
	}
	return result;
  }            
  /** filter out the carriage returns and ampersand symbols in the string. 
   **/
  public static String filter(String s){
	String s2 = replaceStr(s, "&amp;", "and");
	String result = "";
	for (int i = 0; i < s2.length(); i++) {
	  char ch = s2.charAt(i);
	  switch (ch) {
	  case '&' : result += "and";
	  case '\r':
	  case '\n': {
	    break;
	  }
	  default: {
	    result += ch;
	  }
	  }
	}
	return result;
  }            
  /** filter out the spaces in the string.
   **/
  public static String filterSpaces(String s){
		String str = "";
		int len = (s != null) ? s.length() : 0;
		for (int i = 0; i < len; i++) {
		  char ch = s.charAt(i);
		  switch (ch) {
		  case ' ': break;
		  default : str+=ch;
		  }
		}
		return str;
  }            
  /** inverse the hashtable.
   **/
  public static Hashtable inverse(Hashtable ht){
	if (ht==null) return null;
	Hashtable result=new Hashtable();
	Enumeration keys = ht.keys();
	while(keys.hasMoreElements()){
	  Object key = keys.nextElement();
	  Object value = ht.get(key);
	  result.put(value, key);
	}
	return result;
  }            
  /**
   ** Method : isANumber (String)
   ** Purpose: Tests if a String can be parsed as a number.
   **/
  public static boolean isANumber(String input) {
	StringTokenizer st = new StringTokenizer(input, "1234567890., ");
	if (st.hasMoreTokens())
	  return false;
	return true;
  }            
public static String lastOfDottedName(String dottedName) {
 	StringTokenizer st= new StringTokenizer(dottedName,".");
 	int number = st.countTokens();
 	for(int i=0;i<number-1;i++){st.nextToken();}
 	if (st.hasMoreTokens()) {return st.nextToken();
 	} else return "";
}/*
 * Insert the method's description here.
 * Creation date: (1/17/01 3:24:54 PM)
 */      
  /** show a long message.
   **/
  public static void longMessage(String s){
	JTextArea text = new JTextArea(s, 20, 40);
	JPanel p = new JPanel();
	p.add(text);
	JFrame frame = new JFrame();
	frame.getContentPane().add(p);
	frame.setVisible(true);
  }            
  /** show a message.
   **/
  public static void message(Object s){

	/**if(XIBData.isApp)
	  JOptionPane.showMessageDialog(null,s);
	**/
	if (s instanceof String)
	  System.out.println((String)s);
  }            
  /**
   ** Method : minIndex (String, String, String)
   ** Purpose: Compares where 'in1' and 'in2' are located in String 'input', and returns
   **          the smaller positive index of the two.
   **/
  public static int minIndex(String input, String in1, String in2) {
	int index1 = input.indexOf(in1);
	int index2 = input.indexOf(in2);
	if (index1 == -1) return index2;
	else if (index2 == -1) return index1;
	else return Math.min(index1, index2);

⌨️ 快捷键说明

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