|
From: <pe...@us...> - 2004-02-19 15:39:43
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16429/src/java/org/neuclear/commons Modified Files: Utility.java Log Message: Various cleanups and corrections Index: Utility.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/Utility.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Utility.java 19 Dec 2003 18:02:53 -0000 1.5 --- Utility.java 19 Feb 2004 15:29:11 -0000 1.6 *************** *** 2,5 **** --- 2,8 ---- * $Id$ * $Log$ + * Revision 1.6 2004/02/19 15:29:11 pelle + * Various cleanups and corrections + * * Revision 1.5 2003/12/19 18:02:53 pelle * Revamped a lot of exception handling throughout the framework, it has been simplified in most places: *************** *** 141,151 **** package org.neuclear.commons; - import org.neuclear.commons.NeuClearException; - import java.io.*; - import java.util.regex.Pattern; import java.util.regex.Matcher; public final class Utility { public static boolean isEmpty(final Object obj) { return (obj == null || obj.toString().equals("")); --- 144,156 ---- package org.neuclear.commons; import java.io.*; import java.util.regex.Matcher; + import java.util.regex.Pattern; public final class Utility { + + private Utility() { + } + public static boolean isEmpty(final Object obj) { return (obj == null || obj.toString().equals("")); *************** *** 200,234 **** } ! public static int getEnumVal(final String[] enum, final String key) { ! return getEnumVal(enum, key, -1); } ! public static int getEnumVal(final String[] enum, final String key, final int def) { ! if (enum == null || key == null) return def; ! for (int i = 0; i < enum.length; i++) ! if (key.equals(enum[i])) return i; return def; } /** * Asks the User Y/N on the Console * @return */ ! public static boolean getAffirmative(final boolean def) { ! final String prompt = def?"(yes)/no":"yes/(no)"; ! String line=prompt(prompt).toLowerCase(); System.out.println(); if (isEmpty(line)) return def; ! return (line.equals("y")||line.equals("yes")); } ! public static String prompt(String prompt) { System.out.print(prompt); return readLine(); } ! public static String readLine() { ! BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); try { return reader.readLine(); --- 205,242 ---- } ! public static int getEnumVal(final String[] enumArray, final String key) { ! return getenumArrayVal(enumArray, key, -1); } ! public static int getenumArrayVal(final String[] enumArray, final String key, final int def) { ! if (enumArray == null || key == null) return def; ! for (int i = 0; i < enumArray.length; i++) ! if (key.equals(enumArray[i])) return i; return def; } + /** * Asks the User Y/N on the Console + * * @return */ ! public static boolean getAffirmative(final boolean def) { ! final String prompt = def ? "(yes)/no" : "yes/(no)"; ! String line = prompt(prompt).toLowerCase(); System.out.println(); if (isEmpty(line)) return def; ! return (line.equals("y") || line.equals("yes")); } ! public static String prompt(String prompt) { System.out.print(prompt); return readLine(); } ! ! public static String readLine() { ! BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { return reader.readLine(); *************** *** 238,261 **** } ! public static String getExecutable(Class reference){ ! Pattern p=Pattern.compile("\\."); ! Matcher m=p.matcher(reference.getName()); ! String classfile=m.replaceAll("/")+".class"; ! String url=reference.getClassLoader().getResource(classfile).toExternalForm(); ! Pattern r2=Pattern.compile("^jar:file:(.*)!/.*$"); ! Matcher m2=r2.matcher(url); ! if(m2.matches()){ ! String path=m2.group(1); ! String cd=System.getProperty("user.dir"); if (path.startsWith(cd)) ! return SYSTEM_PROMPT+"java -jar "+path.substring(cd.length()+1); ! return SYSTEM_PROMPT+"java -jar "+path; } ! return SYSTEM_PROMPT+"java "+reference.getName(); } ! private static String getSystemConsolePrompt(){ ! return (File.separatorChar=='/')?(System.getProperty("user.name")+"$ "):("C:\\"+System.getProperty("user.dir")+">"); } ! final static public String SYSTEM_PROMPT=getSystemConsolePrompt(); } --- 246,270 ---- } ! public static String getExecutable(Class reference) { ! Pattern p = Pattern.compile("\\."); ! Matcher m = p.matcher(reference.getName()); ! String classfile = m.replaceAll("/") + ".class"; ! String url = reference.getClassLoader().getResource(classfile).toExternalForm(); ! Pattern r2 = Pattern.compile("^jar:file:(.*)!/.*$"); ! Matcher m2 = r2.matcher(url); ! if (m2.matches()) { ! String path = m2.group(1); ! String cd = System.getProperty("user.dir"); if (path.startsWith(cd)) ! return SYSTEM_PROMPT + "java -jar " + path.substring(cd.length() + 1); ! return SYSTEM_PROMPT + "java -jar " + path; } ! return SYSTEM_PROMPT + "java " + reference.getName(); } ! private static String getSystemConsolePrompt() { ! return (File.separatorChar == '/') ? (System.getProperty("user.name") + "$ ") : ("C:\\" + System.getProperty("user.dir") + ">"); } ! ! final static public String SYSTEM_PROMPT = getSystemConsolePrompt(); } |