This repository has been archived by the owner on Apr 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCL.java
281 lines (275 loc) · 7.42 KB
/
CL.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/* CL.java - Copyright (c) 2005 by Stefan Thesing
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
*/
package de.webdings.tools;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* CL (command line) gives basic simple command line
* features. The "out"-methods simply print out data,
* while the "lineOut"-methods print out data followed
* by a line break.
* The "in*"-Methods read data from keyboard input
* followed by pressing of the Enter-key.
*
* CL was created to make it easy for developers to
* use command-line interactivity in their
* Java-programs.
*
* @author Stefan Thesing<br>
* Website: <a href="http://www.webdings.de">http://www.webdings.de</a>
* @version 1.0.1 26.05.2005
*/
public class CL {
// Methods
/**
* Prints out the contents of v to the console.
* @param v The variable to be given out by the program
*/
public static void out(String v) {
System.out.print(v);
}
/**
* Prints out the contents of v to the console.
* @param v The variable to be given out by the program
*/
public static void out(int v) {
System.out.print(v);
}
/**
* Prints out the contents of v to the console.
* @param v The variable to be given out by the program
*/
public static void out(boolean v) {
System.out.print(v);
}
/**
* Prints out the contents of v to the console.
* @param v The variable to be given out by the program
*/
public static void out(float v) {
System.out.print(v);
}
/**
* Prints out the contents of v to the console.
* @param v The variable to be given out by the program
*/
public static void out(short v) {
System.out.print(v);
}
/**
* Prints out the contents of v to the console.
* @param v The variable to be given out by the program
*/
public static void out(double v) {
System.out.print(v);
}
/**
* Prints out the contents of v to the console.
* @param v The variable to be given out by the program
*/
public static void out(char v) {
System.out.print(v);
}
/**
* Prints out the contents of v to the console.
* @param v The variable to be given out by the program
*/
public static void out(char[] v) {
System.out.print(v);
}
/**
* Prints out the contents of v to the console.
* @param v The variable to be given out by the program
*/
public static void out(Object v) {
System.out.print(v);
}
/**
* Prints out the contents of v to the console.
* @param v The variable to be given out by the program
*/
public static void out(long v) {
System.out.print(v);
}
/**
* Prints out the contents of v to the console,
* followed by a line break.
* @param v The variable to be given out by the program
*/
public static void lineOut(String v) {
System.out.println(v);
}
/**
* Prints out the contents of v to the console,
* followed by a line break.
* @param v The variable to be given out by the program
*/
public static void lineOut(int v) {
System.out.println(v);
}
/**
* Prints out the contents of v to the console,
* followed by a line break.
* @param v The variable to be given out by the program
*/
public static void lineOut(boolean v) {
System.out.println(v);
}
/**
* Prints out the contents of v to the console,
* followed by a line break.
* @param v The variable to be given out by the program
*/
public static void lineOut(float v) {
System.out.println(v);
}
/**
* Prints out the contents of v to the console,
* followed by a line break.
* @param v The variable to be given out by the program
*/
public static void lineOut(short v) {
System.out.println(v);
}
/**
* Prints out the contents of v to the console,
* followed by a line break.
* @param v The variable to be given out by the program
*/
public static void lineOut(double v) {
System.out.println(v);
}
/**
* Prints out the contents of v to the console,
* followed by a line break.
* @param v The variable to be given out by the program
*/
public static void lineOut(char v) {
System.out.println(v);
}
/**
* Prints out the contents of v to the console,
* followed by a line break.
* @param v The variable to be given out by the program
*/
public static void lineOut(char[] v) {
System.out.println(v);
}
/**
* Prints out the contents of v to the console,
* followed by a line break.
* @param v The variable to be given out by the program
*/
public static void lineOut(Object v) {
System.out.println(v);
}
/**
* Prints out the contents of v to the console,
* followed by a line break.
* @param v The variable to be given out by the program
*/
public static void lineOut(long v) {
System.out.println(v);
}
/**
* Prints out an empty line followed by a line break.
* Identical to {@link de.webdings.tools.CL#newLine()}.
*/
public static void lineOut() {
System.out.println();
}
/**
* Prints out an empty line followed by a line break.
* Identical to {@link de.webdings.tools.CL#lineOut()}.
*/
public static void newLine() {
lineOut();
}
/**
* @return a string read from keyboard user input.
* @throws IOException
*/
public static String inString() throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine();
s = s.trim();
return s;
}
/**
* @return an int read from keyboard user input.
* @throws IOException
* @throws NumberFormatException
*/
public static int inInt() throws IOException, NumberFormatException {
return Integer.parseInt(inString());
}
/**
* is used for simple "yes or no"-Questions.
* It reads user input and returns <code>true</code>
* for "y", "Y", "yes", "YES", "yES", "yEs", "YEs" and
* <code>false</code> for "n", "N", "no", "NO", "nO", "No".<br>
* For anything else it will output "bad argument!"
* and restart the method.
*
* @return true for yes and false for no
* @throws IOException
*/
public static boolean inYN() throws IOException {
String s = inString();
boolean b = false;
if(s.equals("y")||
s.equals("Y")||
s.equals("yes")||
s.equals("YES")||
s.equals("yES")||
s.equals("yEs")||
s.equals("YEs")) {
b=true;
} else if(s.equals("n")||
s.equals("N")||
s.equals("no")||
s.equals("NO")||
s.equals("nO")||
s.equals("No")) {
b=false;
} else {
System.out.println("bad argument!");
b = inYN();
}
return b;
}
/**
* @return a float read from keyboard user input.
* @throws IOException
* @throws NumberFormatException
*/
public static float inFloat() throws IOException, NumberFormatException {
return Float.parseFloat(inString());
}
/**
* @return a short read from keyboard user input.
* @throws IOException
* @throws NumberFormatException
*/
public static short inShort() throws IOException, NumberFormatException {
return Short.parseShort(inString());
}
/**
* @return a long read from keyboard user input.
* @throws IOException
* @throws NumberFormatException
*/
public static long inLong() throws IOException, NumberFormatException {
return Long.parseLong(inString());
}
}