Webdings Tools (1.0.1) | ||
Frames | No Frames |
1: /* CL.java - Copyright (c) 2005 by Stefan Thesing 2: <p>This file is part of Webdings Tools.</p> 3: <p>Webdings Tools is free software; you can redistribute it and/or modify 4: it under the terms of the GNU General Public License as published by 5: the Free Software Foundation; either version 2 of the License, or 6: (at your option) any later version.</p> 7: <p>Webdings Tools is distributed in the hope that it will be useful, 8: but WITHOUT ANY WARRANTY; without even the implied warranty of 9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10: GNU General Public License for more details.</p> 11: <p>You should have received a copy of the GNU General Public License 12: along with Webdings Tools; if not, write to the<br> 13: Free Software Foundation, Inc.,<br> 14: 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA<br> 15: */ 16: package de.webdings.tools; 17: 18: import java.io.BufferedReader; 19: import java.io.IOException; 20: import java.io.InputStreamReader; 21: 22: /** 23: * CL (command line) gives basic simple command line 24: * features. The "out"-methods simply print out data, 25: * while the "lineOut"-methods print out data followed 26: * by a line break. 27: * The "in*"-Methods read data from keyboard input 28: * followed by pressing of the Enter-key. 29: * 30: * CL was created to make it easy for developers to 31: * use command-line interactivity in their 32: * Java-programs. 33: * 34: * @author Stefan Thesing<br> 35: * Website: <a href="http://www.webdings.de">http://www.webdings.de</a> 36: * @version 1.0.1 26.05.2005 37: */ 38: public class CL { 39: // Methods 40: /** 41: * Prints out the contents of v to the console. 42: * @param v The variable to be given out by the program 43: */ 44: public static void out(String v) { 45: System.out.print(v); 46: } 47: /** 48: * Prints out the contents of v to the console. 49: * @param v The variable to be given out by the program 50: */ 51: public static void out(int v) { 52: System.out.print(v); 53: } 54: /** 55: * Prints out the contents of v to the console. 56: * @param v The variable to be given out by the program 57: */ 58: public static void out(boolean v) { 59: System.out.print(v); 60: } 61: /** 62: * Prints out the contents of v to the console. 63: * @param v The variable to be given out by the program 64: */ 65: public static void out(float v) { 66: System.out.print(v); 67: } 68: /** 69: * Prints out the contents of v to the console. 70: * @param v The variable to be given out by the program 71: */ 72: public static void out(short v) { 73: System.out.print(v); 74: } 75: /** 76: * Prints out the contents of v to the console. 77: * @param v The variable to be given out by the program 78: */ 79: public static void out(double v) { 80: System.out.print(v); 81: } 82: /** 83: * Prints out the contents of v to the console. 84: * @param v The variable to be given out by the program 85: */ 86: public static void out(char v) { 87: System.out.print(v); 88: } 89: /** 90: * Prints out the contents of v to the console. 91: * @param v The variable to be given out by the program 92: */ 93: public static void out(char[] v) { 94: System.out.print(v); 95: } 96: /** 97: * Prints out the contents of v to the console. 98: * @param v The variable to be given out by the program 99: */ 100: public static void out(Object v) { 101: System.out.print(v); 102: } 103: /** 104: * Prints out the contents of v to the console. 105: * @param v The variable to be given out by the program 106: */ 107: public static void out(long v) { 108: System.out.print(v); 109: } 110: /** 111: * Prints out the contents of v to the console, 112: * followed by a line break. 113: * @param v The variable to be given out by the program 114: */ 115: public static void lineOut(String v) { 116: System.out.println(v); 117: } 118: /** 119: * Prints out the contents of v to the console, 120: * followed by a line break. 121: * @param v The variable to be given out by the program 122: */ 123: public static void lineOut(int v) { 124: System.out.println(v); 125: } 126: /** 127: * Prints out the contents of v to the console, 128: * followed by a line break. 129: * @param v The variable to be given out by the program 130: */ 131: public static void lineOut(boolean v) { 132: System.out.println(v); 133: } 134: /** 135: * Prints out the contents of v to the console, 136: * followed by a line break. 137: * @param v The variable to be given out by the program 138: */ 139: public static void lineOut(float v) { 140: System.out.println(v); 141: } 142: /** 143: * Prints out the contents of v to the console, 144: * followed by a line break. 145: * @param v The variable to be given out by the program 146: */ 147: public static void lineOut(short v) { 148: System.out.println(v); 149: } 150: /** 151: * Prints out the contents of v to the console, 152: * followed by a line break. 153: * @param v The variable to be given out by the program 154: */ 155: public static void lineOut(double v) { 156: System.out.println(v); 157: } 158: /** 159: * Prints out the contents of v to the console, 160: * followed by a line break. 161: * @param v The variable to be given out by the program 162: */ 163: public static void lineOut(char v) { 164: System.out.println(v); 165: } 166: /** 167: * Prints out the contents of v to the console, 168: * followed by a line break. 169: * @param v The variable to be given out by the program 170: */ 171: public static void lineOut(char[] v) { 172: System.out.println(v); 173: } 174: /** 175: * Prints out the contents of v to the console, 176: * followed by a line break. 177: * @param v The variable to be given out by the program 178: */ 179: public static void lineOut(Object v) { 180: System.out.println(v); 181: } 182: /** 183: * Prints out the contents of v to the console, 184: * followed by a line break. 185: * @param v The variable to be given out by the program 186: */ 187: public static void lineOut(long v) { 188: System.out.println(v); 189: } 190: /** 191: * Prints out an empty line followed by a line break. 192: * Identical to {@link de.webdings.tools.CL#newLine()}. 193: */ 194: public static void lineOut() { 195: System.out.println(); 196: } 197: /** 198: * Prints out an empty line followed by a line break. 199: * Identical to {@link de.webdings.tools.CL#lineOut()}. 200: */ 201: public static void newLine() { 202: lineOut(); 203: } 204: /** 205: * @return a string read from keyboard user input. 206: * @throws IOException 207: */ 208: public static String inString() throws IOException { 209: BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 210: String s = reader.readLine(); 211: s = s.trim(); 212: return s; 213: } 214: /** 215: * @return an int read from keyboard user input. 216: * @throws IOException 217: * @throws NumberFormatException 218: */ 219: public static int inInt() throws IOException, NumberFormatException { 220: return Integer.parseInt(inString()); 221: } 222: /** 223: * is used for simple "yes or no"-Questions. 224: * It reads user input and returns <code>true</code> 225: * for "y", "Y", "yes", "YES", "yES", "yEs", "YEs" and 226: * <code>false</code> for "n", "N", "no", "NO", "nO", "No".<br> 227: * For anything else it will output "bad argument!" 228: * and restart the method. 229: * 230: * @return true for yes and false for no 231: * @throws IOException 232: */ 233: public static boolean inYN() throws IOException { 234: String s = inString(); 235: boolean b = false; 236: if(s.equals("y")|| 237: s.equals("Y")|| 238: s.equals("yes")|| 239: s.equals("YES")|| 240: s.equals("yES")|| 241: s.equals("yEs")|| 242: s.equals("YEs")) { 243: b=true; 244: } else if(s.equals("n")|| 245: s.equals("N")|| 246: s.equals("no")|| 247: s.equals("NO")|| 248: s.equals("nO")|| 249: s.equals("No")) { 250: b=false; 251: } else { 252: System.out.println("bad argument!"); 253: b = inYN(); 254: } 255: return b; 256: } 257: /** 258: * @return a float read from keyboard user input. 259: * @throws IOException 260: * @throws NumberFormatException 261: */ 262: public static float inFloat() throws IOException, NumberFormatException { 263: return Float.parseFloat(inString()); 264: } 265: /** 266: * @return a short read from keyboard user input. 267: * @throws IOException 268: * @throws NumberFormatException 269: */ 270: public static short inShort() throws IOException, NumberFormatException { 271: return Short.parseShort(inString()); 272: } 273: /** 274: * @return a long read from keyboard user input. 275: * @throws IOException 276: * @throws NumberFormatException 277: */ 278: public static long inLong() throws IOException, NumberFormatException { 279: return Long.parseLong(inString()); 280: } 281: }
Webdings Tools (1.0.1) |
© 2005 by Stefan Thesing;
Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.