-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseString.java
59 lines (51 loc) · 1.56 KB
/
BaseString.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
package cx.nmluci.palindrome;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BaseString {
protected String data;
protected Integer length;
protected String dataType;
public BaseString() {
dataType = "BaseString";
}
public BaseString(String content) {
data = content;
length = data.length();
if (length < 255) {
data = null;
}
}
public BaseString(String[] contents) {
data = "";
if (contents.length == 1) {
data = contents[0];
} else {
for (String content: contents) {
if (content != null) data = data.concat(content);
}
}
length = data.length();
}
public Integer length() {
return length;
}
public String getContent() {
return data;
}
protected void getInput() {
try {
System.out.printf("[%s] Enter your string: ", dataType);
BufferedReader reader = new BufferedReader(new InputStreamReader((System.in)));
String buff = reader.readLine();
if (buff.length() < 255) {
System.out.println("string length has to be at least 255 characters");
} else {
data = buff;
length = data.length();
}
} catch (IOException exception) {
System.out.println("an error occurred during reading from IOStream");
}
}
}