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

📄 genericpropertiescreator.java

📁 Java 编写的多种数据挖掘算法 包括聚类、分类、预处理等
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	String name = enm.nextElement().toString();	// new Hashtable for key	Hashtable t = new Hashtable();	m_Excludes.put(name, t);	t.put(EXCLUDE_INTERFACE, new Vector());	t.put(EXCLUDE_CLASS, new Vector());	t.put(EXCLUDE_SUPERCLASS, new Vector());		// process entries	StringTokenizer tok = new StringTokenizer(p.getProperty(name), ",");	while (tok.hasMoreTokens()) {	  String item = tok.nextToken();	  // get list	  Vector list = new Vector();	  if (item.startsWith(EXCLUDE_INTERFACE + ":"))	    list = (Vector) t.get(EXCLUDE_INTERFACE);	  else if (item.startsWith(EXCLUDE_CLASS + ":"))	    list = (Vector) t.get(EXCLUDE_CLASS);	  else if (item.startsWith(EXCLUDE_SUPERCLASS))	    list = (Vector) t.get(EXCLUDE_SUPERCLASS);	  // add to list	  list.add(item.substring(item.indexOf(":") + 1));	}      }    }    catch (Exception e) {      e.printStackTrace();    }  }  /**   * checks whether the classname is a valid one, i.e., from a public class   *   * @param classname   the classname to check   * @return            whether the classname is a valid one   */  protected boolean isValidClassname(String classname) {    return (classname.indexOf("$") == -1);  }  /**   * Checks whether the classname is a valid one for the given key. This is   * based on the settings in the Exclude file.   *   * @param key         the property key   * @param classname   the classname to check   * @return            whether the classname is a valid one   * @see		#EXCLUDE_FILE   */  protected boolean isValidClassname(String key, String classname) {    boolean	result;    Class	cls;    Class	clsCurrent;    Vector	list;    int		i;    result = true;    // are there excludes for this key?    if (m_Excludes.containsKey(key)) {      try {	clsCurrent = Class.forName(classname);      }      catch (Exception e) {	// we ignore this Exception	clsCurrent = null;      }            // interface      if ((clsCurrent != null) && result) {	list = (Vector) ((Hashtable) m_Excludes.get(key)).get(EXCLUDE_INTERFACE);	for (i = 0; i < list.size(); i++) {	  try {	    cls = Class.forName(list.get(i).toString());	    if (ClassDiscovery.hasInterface(cls, clsCurrent)) {	      result = false;	      break;	    }	  }	  catch (Exception e) {	    // we ignore this Exception	  }	}      }            // superclass      if ((clsCurrent != null) && result) {	list = (Vector) ((Hashtable) m_Excludes.get(key)).get(EXCLUDE_SUPERCLASS);	for (i = 0; i < list.size(); i++) {	  try {	    cls = Class.forName(list.get(i).toString());	    if (ClassDiscovery.isSubclass(cls, clsCurrent)) {	      result = false;	      break;	    }	  }	  catch (Exception e) {	    // we ignore this Exception	  }	}      }            // class      if ((clsCurrent != null) && result) {	list = (Vector) ((Hashtable) m_Excludes.get(key)).get(EXCLUDE_CLASS);	for (i = 0; i < list.size(); i++) {	  try {	    cls = Class.forName(list.get(i).toString());	    if (cls.getName().equals(clsCurrent.getName()))	      result = false;	  }	  catch (Exception e) {	    // we ignore this Exception	  }	}      }    }    return result;  }    /**   * fills in all the classes (based on the packages in the input properties    * file) into the output properties file   *        * @throws Exception 	if something goes wrong   * @see #m_OutputProperties   */  protected void generateOutputProperties() throws Exception {    Enumeration       keys;    String            key;    String            value;    String            pkg;    StringTokenizer   tok;    Vector            classes;    int               i;        m_OutputProperties = new Properties();    keys             = m_InputProperties.propertyNames();    while (keys.hasMoreElements()) {      key   = keys.nextElement().toString();      tok   = new StringTokenizer(m_InputProperties.getProperty(key), ",");      value = "";      // get classes for all packages      while (tok.hasMoreTokens()) {        pkg = tok.nextToken().trim();                try {          classes = ClassDiscovery.find(Class.forName(key), pkg);        }        catch (Exception e) {          System.out.println("Problem with '" + key + "': " + e);          classes = new Vector();        }                for (i = 0; i < classes.size(); i++) {          // skip non-public classes          if (!isValidClassname(classes.get(i).toString()))            continue;          // some classes should not be listed for some keys          if (!isValidClassname(key, classes.get(i).toString()))            continue;          if (!value.equals(""))            value += ",";          value += classes.get(i).toString();        }        if (VERBOSE)          System.out.println(pkg + " -> " + value);      }      m_OutputProperties.setProperty(key, value);    }  }    /**   * stores the generated output properties file   *    * @throws Exception	if the saving fails   * @see #m_OutputProperties   * @see #m_OutputFilename    */  protected void storeOutputProperties() throws Exception {    if (VERBOSE)      System.out.println("Saving '" + getOutputFilename() + "'...");    m_OutputProperties.store(        new FileOutputStream(getOutputFilename()),         " Customises the list of options given by the GenericObjectEditor\n# for various superclasses.");  }    /**   * generates the props-file for the GenericObjectEditor and stores it   *    * @throws Exception	if something goes wrong   * @see #execute(boolean)   */  public void execute() throws Exception {    execute(true);  }    /**   * generates the props-file for the GenericObjectEditor and stores it only   * if the the param <code>store</code> is TRUE. If it is FALSE then the   * generated properties file can be retrieved via the <code>getOutputProperties</code>   * method.    *    * @param store     	if TRUE then the properties file is stored to the stored    *                  	filename   * @throws Exception	if something goes wrong   * @see #getOutputFilename()   * @see #setOutputFilename(String)   * @see #getOutputProperties()   */  public void execute(boolean store) throws Exception {    // read properties file    loadInputProperties();        // generate the props file    generateOutputProperties();        // write properties file    if (store)      storeOutputProperties();  }    /**   * for generating props file:   * <ul>   *   <li>   *     no parameter:    *     see default constructor   *   </li>   *   <li>   *     1 parameter (i.e., filename):    *     see default constructor + setOutputFilename(String)   *   </li>   *   <li>   *     2 parameters (i.e, filenames):    *     see constructor with String argument + setOutputFilename(String)   *   </li>   * </ul>   *   * @param args	the commandline arguments   * @throws Exception 	if something goes wrong   * @see #GenericPropertiesCreator()   * @see #GenericPropertiesCreator(String)   * @see #setOutputFilename(String)   */  public static void main(String[] args) throws Exception {    GenericPropertiesCreator   c = null;        if (args.length == 0) {      c = new GenericPropertiesCreator();    }    else if (args.length == 1) {      c = new GenericPropertiesCreator();      c.setOutputFilename(args[0]);    }    else if (args.length == 2) {      c = new GenericPropertiesCreator(args[0]);      c.setOutputFilename(args[1]);    }    else {      System.out.println("usage: " + GenericPropertiesCreator.class.getName() + " [<input.props>] [<output.props>]");      System.exit(1);    }        c.execute(true);  }}

⌨️ 快捷键说明

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