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

📄 orditools.java

📁 为了下东西 随便发了个 datamining 的源代码
💻 JAVA
字号:
/* *    This program is free software; you can redistribute it and/or modify *    it under the terms of the GNU General Public License as published by *    the Free Software Foundation; either version 2 of the License, or *    (at your option) any later version. * *    This program is distributed in the hope that it will be useful, *    but WITHOUT ANY WARRANTY; without even the implied warranty of *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *    GNU General Public License for more details. * *    You should have received a copy of the GNU General Public License *    along with this program; if not, write to the Free Software *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* * Created on 2006/8/17 * * @Author: Xiaojun Chen * $Revision$ 1.0 * */package eti.bi.alphaminer.tools;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;import java.io.Reader;import java.text.NumberFormat;import eti.bi.common.System.SystemVariable;public class OrdiTools {    	/** Used for formatting values in the {@link #formatNumber(double)} method. */	private static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance();	/** Used for formatting values in the {@link #formatPercent(double)} method. */	private static final NumberFormat PERCENT_FORMAT = NumberFormat.getPercentInstance();		/**	 * Returns a formatted string of the given number (percent format with two	 * fraction digits).	 */	public static String formatPercent(double value) {		int percentDigits = 2;		try {			String percentDigitsString = SystemVariable.getSystemProperty("alphaminer.fractiondigits.percent");			percentDigits = Integer.parseInt(percentDigitsString);		} catch (NumberFormatException e) {}		PERCENT_FORMAT.setMaximumFractionDigits(percentDigits);		return PERCENT_FORMAT.format(value);	}	/**	 * Returns a formatted string of the given number (number format with	 * usually three fraction digits).	 */	public static String formatNumber(double value) {		int numberDigits = 3;		try {			String numberDigitsString = SystemVariable.getSystemProperty("alphaminer.fractiondigits.numbers");			numberDigits = Integer.parseInt(numberDigitsString);		} catch (NumberFormatException e) {}		NUMBER_FORMAT.setMaximumFractionDigits(numberDigits);		return NUMBER_FORMAT.format(value);	}	/**	 * Returns a formatted string of the given number (number format with three	 * fraction digits).	 */	public static String formatNumber(double value, int numberOfDigits) {		NUMBER_FORMAT.setMaximumFractionDigits(numberOfDigits);		NUMBER_FORMAT.setMinimumFractionDigits(numberOfDigits);		return NUMBER_FORMAT.format(value);	}        /** Returns a number string with no fraction digits if possible. Otherwise the complete digits will be returned. */    public static String formatIntegerIfPossible(double value) {        int intValue = (int)value;        if (intValue == value) {            return intValue + "";        } else {            return value + "";        }    }	/** Returns the name for an ordinal number. */	public static final String ordinalNumber(int n) {		if ((n % 10 == 1) && (n % 100 != 11)) {			return n + "st";		}		if ((n % 10 == 2) && (n % 100 != 12)) {			return n + "nd";		}		if ((n % 10 == 3) && (n % 100 != 13)) {			return n + "rd";		}		return n + "th";	}	/**	 * Returns the class name of the given class without the package	 * information.	 */	public static String classNameWOPackage(Class c) {		return c.getName().substring(c.getName().lastIndexOf(".") + 1);	}	/**	 * Reads the output of the reader and delivers it at string.	 */	public static String readOutput(BufferedReader in) throws IOException {		StringBuffer output = new StringBuffer();		String line = "";		while ((line = in.readLine()) != null) {			output.append(line);			output.append("\n");		}		return output.toString();	}	/**	 * Creates a file relative to the given parent if name is not an absolute	 * file name. Returns null if name is null.	 */	public static File getFile(File parent, String name) {		if (name == null)			return null;		File file = new File(name);		if (file.isAbsolute())			return file;		else			return new File(parent, name);	}	/**	 * Creates a directory including parent directories.	 * 	 * @return true, if operation was successful.	 */	public static boolean mkdir(File dir) {		if (dir == null)			return true;		if (dir.exists())			return true;		File parent = dir.getParentFile();		if (parent == null) {			return true;		} else if (!parent.exists()) {			if (!mkdir(parent))				return false;		}		return dir.mkdir();	}		public static String readTextFile(File file) throws IOException {		return readTextFile(new FileReader(file));	}	public static String readTextFile(Reader r) throws IOException {		StringBuffer contents = new StringBuffer();		BufferedReader reader = new BufferedReader(r);		String line = "";		while ((line = reader.readLine()) != null) {			contents.append(line + "\n");		}		reader.close();		return contents.toString();	}	public static final String[] TRUE_STRINGS = { "true", "on", "yes", "y" };	public static final String[] FALSE_STRINGS = { "false", "off", "no", "n" };	public static boolean booleanValue(String string, boolean deflt) {		if (string == null)			return deflt;		string = string.toLowerCase().trim();		for (int i = 0; i < TRUE_STRINGS.length; i++) {			if (TRUE_STRINGS[i].equals(string)) {				return true;			}		}		for (int i = 0; i < FALSE_STRINGS.length; i++) {			if (FALSE_STRINGS[i].equals(string)) {				return false;			}		}		return deflt;	}		/**	 * @param aFilename a file name	 * @return the short name of file, without predix	 * */	public static String shortFilename(String aFilename) {		if(aFilename==null) {			return null;		}		if(aFilename.length()==0) {			return aFilename;		}		int index = aFilename.indexOf(".");		if(index>0) {			aFilename = aFilename.substring(0, index);		}		else if(index==0) {			return "";		}				char[] chars = aFilename.toCharArray();		if(chars[chars.length-1]=='/'||chars[chars.length-1]=='\\') {			return "";		}				if(chars.length==1) {			return aFilename;		}				for(int i=chars.length-2;i>=0;i--) {			if(chars[i]=='\\'||chars[i]=='/') {				return new String(chars,i+1,chars.length-i-1);			}		}				return aFilename;	}		public static void main(String[] args) {		System.out.println(shortFilename("d:/d\\c.doc"));	}}

⌨️ 快捷键说明

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