📄 technicalinformation.java
字号:
return generateID(); } /** * sets the value for the given field, overwrites any previously existing one. * * @param field the field to set the value for * @param value the value of the field */ public void setValue(Field field, String value) { m_Values.put(field, value); } /** * returns the value associated with the given field, or empty if field is * not currently stored. * * @param field the field to retrieve the value for * @return the value associated with this field, empty if not existing */ public String getValue(Field field) { if (m_Values.containsKey(field)) return (String) m_Values.get(field); else return ""; } /** * returns TRUE if the field is stored and has a value different from the * empty string. * * @param field the field to check * @return true if a value is stored for the field and non-empty */ public boolean exists(Field field) { return ( m_Values.containsKey(field) && (((String) m_Values.get(field)).length() != 0) ); } /** * returns an enumeration over all the stored fields * * @return all currently stored fields */ public Enumeration fields() { return m_Values.keys(); } /** * returns true if there are further technical informations stored in this * * @return true if there are further technical informations available */ public boolean hasAdditional() { return (m_Additional.size() > 0); } /** * returns an enumeration of all the additional technical informations (if * there are any) * * @return an enumeration over all additional technical informations */ public Enumeration additional() { return m_Additional.elements(); } /** * adds the given information to the list of additional technical * informations * * @param value the information to add */ public void add(TechnicalInformation value) { if (value == this) throw new IllegalArgumentException("Can't add object to itself!"); m_Additional.add(value); } /** * Adds an empty technical information with the given type to the list * of additional informations and returns the instance. * * @param type the type of the new information to add * @return the generated information */ public TechnicalInformation add(Type type) { TechnicalInformation result; result = new TechnicalInformation(type); add(result); return result; } /** * Returns a plain-text string representing this technical information. * Note: it only returns a string based on some fields. At least AUTHOR, * YEAR and TITLE are necessary. * * @return a string representation of this information */ public String toString() { String result; String[] authors; int i; Enumeration enm; result = ""; authors = getAuthors(); // BOOK if (getType() == Type.BOOK) { for (i = 0; i < authors.length; i++) { if (i > 0) result += ", "; result += authors[i]; } result += " (" + getValue(Field.YEAR) + ")."; result += " " + getValue(Field.TITLE) + "."; result += " " + getValue(Field.PUBLISHER); if (exists(Field.ADDRESS)) result += ", " + getValue(Field.ADDRESS); result += "."; } // ARTICLE else if (getType() == Type.ARTICLE) { for (i = 0; i < authors.length; i++) { if (i > 0) result += ", "; result += authors[i]; } result += " (" + getValue(Field.YEAR) + ")."; result += " " + getValue(Field.TITLE) + "."; // journal if (exists(Field.JOURNAL)) { result += " " + getValue(Field.JOURNAL) + "."; if (exists(Field.VOLUME)) result += " " + getValue(Field.VOLUME); if (exists(Field.NUMBER)) result += "(" + getValue(Field.NUMBER) + ")"; if (exists(Field.PAGES)) result += ":" + getValue(Field.PAGES); result += "."; } // other than JOURNAL??? // URL if (exists(Field.URL)) result += " URL " + getValue(Field.URL) + "."; } // CONFERENCE/INPROCEEDINGS else if ( (getType() == Type.CONFERENCE) || (getType() == Type.INPROCEEDINGS) ) { for (i = 0; i < authors.length; i++) { if (i > 0) result += ", "; result += authors[i]; } result += ": " + getValue(Field.TITLE) + "."; result += " In: " + getValue(Field.BOOKTITLE); if (exists(Field.ADDRESS)) result += ", " + getValue(Field.ADDRESS); if (exists(Field.PAGES)) result += ", " + getValue(Field.PAGES); result += ", " + getValue(Field.YEAR) + "."; } // INCOLLECTION else if (getType() == Type.INCOLLECTION) { for (i = 0; i < authors.length; i++) { if (i > 0) result += ", "; result += authors[i]; } result += ": " + getValue(Field.TITLE) + "."; result += " In "; if (exists(Field.EDITOR)) result += getValue(Field.EDITOR) + ", editors, "; result += getValue(Field.BOOKTITLE); if (exists(Field.ADDRESS)) result += ", " + getValue(Field.ADDRESS); if (exists(Field.PAGES)) result += ", " + getValue(Field.PAGES); result += ", " + getValue(Field.YEAR) + "."; } // default else { for (i = 0; i < authors.length; i++) { if (i > 0) result += ", "; result += authors[i]; } result += " (" + getValue(Field.YEAR) + ")."; result += " " + getValue(Field.TITLE) + "."; if (exists(Field.ADDRESS)) result += " " + getValue(Field.ADDRESS) + "."; if (exists(Field.URL)) result += " URL " + getValue(Field.URL) + "."; } // additional informations? enm = additional(); while (enm.hasMoreElements()) { result += "\n\n" + enm.nextElement().toString(); } return result; } /** * Returns a BibTex string representing this technical information. * Note: this is just a very raw implementation, special characters need to * be escaped manually for LaTeX. * * @return the BibTeX representation of this information */ public String toBibTex() { String result; Enumeration enm; Field field; Vector list; int i; result = "@" + getType() + "{" + getID() + ""; // sort the fields list = new Vector(); enm = fields(); while (enm.hasMoreElements()) list.add(enm.nextElement()); Collections.sort(list); // list field=value pairs for (i = 0; i < list.size(); i++) { field = (Field) list.get(i); if (!exists(field)) continue; result += ",\n " + field + " = {" + getValue(field) + "}"; } result += "\n}"; // additional informations? enm = additional(); while (enm.hasMoreElements()) { result += "\n\n" + ((TechnicalInformation) enm.nextElement()).toBibTex(); } return result; } /** * Prints some examples of technical informations if there are no * commandline options given. Otherwise the information of a given * TechnicalInformationHandler can be printed. <p/> * * Valid options are: <p/> * * -W classname <br/> * The classname of the TechnicalInformationHandler to print the * information for <p/> * * -bibtex <br/> * Print the information in BibTeX format <p/> * * -plaintext <br/> * Print the information in plain text format <p/> * * @param args the commandline options * @throws Exception if the option parsing fails */ public static void main(String[] args) throws Exception { TechnicalInformation info; TechnicalInformation additional; String tmpStr; Class cls; TechnicalInformationHandler handler; // example from command line if (args.length != 0) { info = null; tmpStr = Utils.getOption('W', args); if (tmpStr.length() != 0) { cls = Class.forName(tmpStr); handler = (TechnicalInformationHandler) cls.newInstance(); info = handler.getTechnicalInformation(); } else { throw new IllegalArgumentException("A classname has to be provided with the -W option!"); } if (Utils.getFlag("bibtex", args)) System.out.println("\n" + handler.getClass().getName() + ":\n" + info.toBibTex()); if (Utils.getFlag("plaintext", args)) System.out.println("\n" + handler.getClass().getName() + ":\n" + info.toString()); } else { // first example info = new TechnicalInformation(Type.BOOK); info.setValue(Field.AUTHOR, "Ross Quinlan"); info.setValue(Field.YEAR, "1993"); info.setValue(Field.TITLE, "C4.5: Programs for Machine Learning"); info.setValue(Field.PUBLISHER, "Morgan Kaufmann Publishers"); info.setValue(Field.ADDRESS, "San Mateo, CA"); additional = info; System.out.println("\ntoString():\n" + info.toString()); System.out.println("\ntoBibTex():\n" + info.toBibTex()); // second example info = new TechnicalInformation(Type.INPROCEEDINGS); info.setValue(Field.AUTHOR, "Freund, Y. and Mason, L."); info.setValue(Field.YEAR, "1999"); info.setValue(Field.TITLE, "The alternating decision tree learning algorithm"); info.setValue(Field.BOOKTITLE, "Proceeding of the Sixteenth International Conference on Machine Learning"); info.setValue(Field.ADDRESS, "Bled, Slovenia"); info.setValue(Field.PAGES, "124-133"); System.out.println("\ntoString():\n" + info.toString()); System.out.println("\ntoBibTex():\n" + info.toBibTex()); // third example info = new TechnicalInformation(Type.ARTICLE); info.setValue(Field.AUTHOR, "R. Quinlan"); info.setValue(Field.YEAR, "1986"); info.setValue(Field.TITLE, "Induction of decision trees"); info.setValue(Field.JOURNAL, "Machine Learning"); info.setValue(Field.VOLUME, "1"); info.setValue(Field.NUMBER, "1"); info.setValue(Field.PAGES, "81-106"); additional = new TechnicalInformation(Type.BOOK); additional.setValue(Field.AUTHOR, "Ross Quinlan"); additional.setValue(Field.YEAR, "1993"); additional.setValue(Field.TITLE, "C4.5: Programs for Machine Learning"); additional.setValue(Field.PUBLISHER, "Morgan Kaufmann Publishers"); additional.setValue(Field.ADDRESS, "San Mateo, CA"); info.add(additional); System.out.println("\ntoString():\n" + info.toString()); System.out.println("\ntoBibTex():\n" + info.toBibTex()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -