Changeset 175
- Timestamp:
- 09/09/11 23:52:51 (13 years ago)
- Location:
- trunk/JavaHelperLib/src/de/ugoe/cs/util
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaHelperLib/src/de/ugoe/cs/util/ArrayTools.java
r1 r175 1 1 package de.ugoe.cs.util; 2 2 3 /** 4 * <p> 5 * Helper class that provides methods to simplify working with arrays. 6 * </p> 7 * 8 * @author Steffen Herbold 9 * @version 1.0 10 */ 3 11 final public class ArrayTools { 4 12 5 13 /** 6 14 * <p> 7 * Finds the first occur ence of an object inside an array.15 * Finds the first occurrence of an object inside an array. 8 16 * </p> 9 17 * <p> 10 * In case {@code other==null}, the first occurence of a {@code null} value in the array is returned. 18 * In case {@code other==null}, the first occurrence of a {@code null} value 19 * in the array is returned. 11 20 * </p> 12 * 13 * @param array the array 14 * @param other the object 21 * 22 * @param array 23 * the array 24 * @param other 25 * the object 15 26 * @return index of the object if found, -1 otherwise 16 27 */ 17 28 public static int findIndex(Object[] array, Object other) { 18 29 int retVal = -1; 19 for ( int i=0 ; i<array.length && retVal==-1 ; i++) {20 if ( other!=null) {21 if ( array[i]!=null && array[i].equals(other)) {30 for (int i = 0; i < array.length && retVal == -1; i++) { 31 if (other != null) { 32 if (array[i] != null && array[i].equals(other)) { 22 33 retVal = i; 23 34 } 24 35 } else { 25 if ( array[i]==null) {36 if (array[i] == null) { 26 37 retVal = i; 27 38 } -
trunk/JavaHelperLib/src/de/ugoe/cs/util/FileTools.java
r83 r175 6 6 import java.io.IOException; 7 7 8 /** 9 * <p> 10 * Helper class that provides methods that simplify working with files. 11 * </p> 12 * 13 * @author Steffen Herbold 14 * @version 1.0 15 */ 8 16 public class FileTools { 9 17 10 18 /** 11 19 * <p> 12 * Returns an array of the lines contained in a file. The line seperator is "\r\n". 20 * Returns an array of the lines contained in a file. The line separator is 21 * "\r\n". 13 22 * </p> 14 * @param filename name of the file 23 * 24 * @param filename 25 * name of the file 15 26 * @return string array, where each line contains a file 16 * @throws IOException see {@link FileReader#read(char[])}, {@link FileReader#close()} 17 * @throws FileNotFoundException see {@link FileReader#FileReader(File)} 27 * @throws IOException 28 * see {@link FileReader#read(char[])}, 29 * {@link FileReader#close()} 30 * @throws FileNotFoundException 31 * see {@link FileReader#FileReader(File)} 18 32 */ 19 public static String[] getLinesFromFile(String filename) throws IOException, FileNotFoundException { 33 public static String[] getLinesFromFile(String filename) 34 throws IOException, FileNotFoundException { 20 35 return getLinesFromFile(filename, true); 21 36 } 22 37 23 38 /** 24 39 * <p> 25 40 * Returns an array of the lines contained in a file. 26 41 * </p> 27 * @param filename name of the file 28 * @param carriageReturn if true, "\r\n", if false "\n" is used as line seperator 42 * 43 * @param filename 44 * name of the file 45 * @param carriageReturn 46 * if true, "\r\n", if false "\n" is used as line separator 29 47 * @return string array, where each line contains a file 30 * @throws IOException see {@link FileReader#read(char[])}, {@link FileReader#close()} 31 * @throws FileNotFoundException see {@link FileReader#FileReader(File)} 48 * @throws IOException 49 * see {@link FileReader#read(char[])}, 50 * {@link FileReader#close()} 51 * @throws FileNotFoundException 52 * see {@link FileReader#FileReader(File)} 32 53 */ 33 public static String[] getLinesFromFile(String filename, boolean carriageReturn) throws IOException, FileNotFoundException { 54 public static String[] getLinesFromFile(String filename, 55 boolean carriageReturn) throws IOException, FileNotFoundException { 34 56 File f = new File(filename); 35 57 FileReader reader = new FileReader(f); … … 38 60 reader.close(); 39 61 String splitString; 40 if ( carriageReturn) {62 if (carriageReturn) { 41 63 splitString = "\r\n"; 42 64 } else { -
trunk/JavaHelperLib/src/de/ugoe/cs/util/StringTools.java
r1 r175 1 1 package de.ugoe.cs.util; 2 2 3 /** 4 * <p> 5 * Helper class that provides methods to simplify working with {@link String}s. 6 * </p> 7 * 8 * @author Steffen Herbold 9 * @version 1.0 10 */ 3 11 final public class StringTools { 4 12 5 public final static String ENDLINE = System.getProperty("line.separator");6 7 13 /** 8 14 * <p> 9 * Replaces all occurences of {@literal &, <, >, ', and "} with their 10 * respective XML entites {@literal &, <, >, ', and "} 15 * Simplifies use of operation system specific line separators. 16 * </p> 17 */ 18 public final static String ENDLINE = System.getProperty("line.separator"); 19 20 /** 21 * <p> 22 * Replaces all occurrences of {@literal &, <, >, ', and "} with their 23 * respective XML entities {@literal &, <, >, ', and "} 11 24 * without destroying already existing entities. 12 25 * </p> 13 26 * 14 27 * @param str 15 * String where the XML entit es are to be replaced16 * @return new String, where the XML entit es are used instead of the28 * String where the XML entities are to be replaced 29 * @return new String, where the XML entities are used instead of the 17 30 * literals 18 31 */ -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/Command.java
r1 r175 11 11 * 12 12 * @author Steffen Herbold 13 * @version 1.0 13 14 */ 14 15 public interface Command { -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/CommandExecuter.java
r1 r175 4 4 import java.util.ArrayList; 5 5 import java.util.List; 6 7 6 8 7 /** … … 14 13 * </p> 15 14 * <p> 16 * This class is implemented as a <i>Singleton</i>. 15 * This class is implemented as a <i>Singleton</i>. 17 16 * </p> 18 17 * 19 18 * @author Steffen Herbold 19 * @version 1.0 20 20 */ 21 21 public class CommandExecuter { … … 34 34 */ 35 35 private static final String cmdPrefix = "CMD"; 36 36 37 37 /** 38 38 * <p> … … 48 48 * </p> 49 49 * <p> 50 * The de faultcommands package has always lowest priority, unless it is51 * specificially added.50 * The de.ugoe.cs.util.console.defaultcommands package has always lowest 51 * priority, unless it is specifically added. 52 52 * </p> 53 53 */ … … 78 78 /** 79 79 * <p> 80 * Adds a package that will be used by exec to load command from. 80 * Adds a package that will be used by {@link #exec(String)} to load command 81 * from. 81 82 * </p> 82 83 * … … 111 112 parser.parse(command); 112 113 for (int i = 0; cmd == null && i < commandPackageList.size(); i++) { 113 cmd = loadCMD(commandPackageList.get(i)+"."+cmdPrefix+parser.getCommandName()); 114 cmd = loadCMD(commandPackageList.get(i) + "." + cmdPrefix 115 + parser.getCommandName()); 114 116 } 115 117 if (cmd == null) { // check if command is available as default command 116 cmd = loadCMD(defaultPackage+"."+cmdPrefix+parser.getCommandName()); 118 cmd = loadCMD(defaultPackage + "." + cmdPrefix 119 + parser.getCommandName()); 117 120 } 118 121 if (cmd == null) { … … 128 131 129 132 /** 133 * <p> 130 134 * Helper method that loads a class and tries to cast it to {@link Command}. 135 * </p> 131 136 * 132 * @param className qualified name of the class (including package name) 133 * @return if class is available and implement {@link Command} and instance of the class, null otherwise 137 * @param className 138 * qualified name of the class (including package name) 139 * @return if class is available and implement {@link Command} and instance 140 * of the class, null otherwise 134 141 */ 135 142 private Command loadCMD(String className) { … … 140 147 } catch (NoClassDefFoundError e) { 141 148 String[] splitResult = e.getMessage().split("CMD"); 142 String correctName = splitResult[splitResult.length-1].replace(")", ""); 149 String correctName = splitResult[splitResult.length - 1].replace( 150 ")", ""); 143 151 Console.traceln("Did you mean " + correctName + "?"); 144 152 } catch (ClassNotFoundException e) { -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/CommandParser.java
r1 r175 10 10 * 11 11 * @author Steffen Herbold 12 * @version 1.0 12 13 */ 13 14 public class CommandParser { -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/Console.java
r1 r175 5 5 6 6 import de.ugoe.cs.util.StringTools; 7 8 7 9 8 /** … … 23 22 * 24 23 * @author Steffen Herbold 24 * @version 1.0 25 25 */ 26 26 public final class Console { … … 120 120 } 121 121 for (ConsoleObserver observer : theInstance.observers) { 122 observer.updateText(msg 123 + StringTools.ENDLINE); 122 observer.updateText(msg + StringTools.ENDLINE); 124 123 } 125 124 } … … 157 156 } 158 157 for (ConsoleObserver observer : theInstance.observers) { 159 observer.errStream(errMsg 160 + StringTools.ENDLINE); 158 observer.errStream(errMsg + StringTools.ENDLINE); 161 159 } 162 160 } … … 200 198 * <p> 201 199 * Sends a debug message to all observers containing the message that was 202 * passed to this function and adds an endline to the message. 200 * passed to this function and adds an {@link StringTools#ENDLINE} to the 201 * message. 203 202 * </p> 204 203 * … … 211 210 } 212 211 for (ConsoleObserver observer : theInstance.observers) { 213 observer.trace(traceMsg 214 + StringTools.ENDLINE); 212 observer.trace(traceMsg + StringTools.ENDLINE); 215 213 } 216 214 } -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/ConsoleObserver.java
r1 r175 7 7 * 8 8 * @author Steffen Herbold 9 * @version 1.0 9 10 */ 10 11 public interface ConsoleObserver { -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/TextConsole.java
r1 r175 6 6 * <p> 7 7 * Implements a simple console observer that prints normal text to 8 * <code>stdout</code>, errors to <code>stderr</code> and reads from 9 * <code>stdin</code>. 8 * {@code stdout}, errors to {@code stderr} and reads from {@code stdin}. 10 9 * </p> 11 10 * 12 11 * @author Steffen Herbold 12 * @version 1.0 13 13 */ 14 14 public class TextConsole implements ConsoleObserver { … … 32 32 /** 33 33 * <p> 34 * Prints messages to <code>stdout</code>.34 * Prints messages to {@code stdout}. 35 35 * </p> 36 36 * … … 43 43 /** 44 44 * <p> 45 * Prints messages to <code>stderr</code>.45 * Prints messages to {@code stderr}. 46 46 * </p> 47 47 * … … 55 55 /** 56 56 * <p> 57 * Prints the stack race of an exception to <code>stderr</code>57 * Prints the stacktrace of an exception to {@code stderr}. 58 58 * </p> 59 59 * … … 67 67 /** 68 68 * <p> 69 * Prints messages to <code>stdout</code>. These messages are only printed,70 * ifthe console is run in debug mode.69 * Prints messages to {@code stdout}. These messages are only printed, if 70 * the console is run in debug mode. 71 71 * </p> 72 72 */ … … 82 82 * Starts a new TextConsole. If the text console is started, it can be used 83 83 * not only to print message, but also to execute commands by reading 84 * <code>stdin</code>.84 * {@code stdin}. 85 85 * </p> 86 86 * … … 103 103 /** 104 104 * <p> 105 * Reads a new command from <code>stdin</code>.105 * Reads a new command from {@code stdin}. 106 106 * </p> 107 107 * -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/defaultcommands/CMDexec.java
r122 r175 14 14 /** 15 15 * <p> 16 * Implements a command to execute batchs of {@link Command}s, defined by batch17 * file, to allow scripted executions.16 * Command to execute a batch of {@link Command}s. The batch is defined as a 17 * text file, where each line defines one command. 18 18 * </p> 19 19 * 20 20 * @author Steffen Herbold 21 * @version 1.0 21 22 */ 22 23 public class CMDexec implements Command { 23 24 24 /** 25 * <p> 26 * Executes a batch of {@link Command}s that are listed line by line in the 27 * given file. 28 * </p> 29 * <p> 30 * Usage: <code>exec filename</code> 31 * </p> 25 /* 26 * (non-Javadoc) 32 27 * 33 * @see de.ugoe.cs.util.console. commands.Command#run(java.util.List)28 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 34 29 */ 35 30 public void run(List<Object> parameters) { -
trunk/JavaHelperLib/src/de/ugoe/cs/util/console/defaultcommands/CMDexit.java
r1 r175 8 8 /** 9 9 * <p> 10 * Implements a command to terminate an application.10 * Command to terminate an application. 11 11 * </p> 12 12 * 13 13 * @author Steffen Herbold 14 * 14 * @version 1.0 15 15 */ 16 16 public class CMDexit implements Command { 17 17 18 /* (non-Javadoc) 18 /* 19 * (non-Javadoc) 20 * 19 21 * @see databasebuilder.console.commands.Command#help() 20 22 */ … … 23 25 Console.println("Usage: exit"); 24 26 } 25 26 /** 27 * <p> 28 * Terminates the programm. 29 * </p> 30 * <p> 31 * Usage: <code>exit</code> 32 * </p> 27 28 /* 29 * (non-Javadoc) 30 * 31 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 33 32 */ 34 33 @Override
Note: See TracChangeset
for help on using the changeset viewer.