-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHiddenView.java
More file actions
57 lines (48 loc) · 1.71 KB
/
Copy pathHiddenView.java
File metadata and controls
57 lines (48 loc) · 1.71 KB
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
package HiddenText;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;
/**
* Author: Aleksey Alekseenko
* Date: 02.08.13
*/
public abstract class HiddenView {
Properties properties;
public abstract StringBuilder hide(StringBuilder string);
public HiddenView() {
properties = loadProperties();
if (isNotValidData()) {
System.out.println("Properties file isn't valid");
System.exit(0);
}
}
private boolean isNotValidData() {
return !(properties.getProperty("hiddenText").equals("true") && properties.getProperty("hiddenText").equals("false")
&& isInteger(properties.getProperty("quantityOfFirstChars"))
&& isInteger(properties.getProperty("quantityOfLastChars"))
&& Integer.parseInt(properties.getProperty("quantityOfFirstChars")) > 0
&& Integer.parseInt(properties.getProperty("quantityOfFirstChars")) > 0);
}
private Properties loadProperties() {
Properties properties = new Properties();
try {
System.out.println("Enter property file location");
Scanner scanner = new Scanner(System.in);
String fileLocation = scanner.next();
properties.load(new FileInputStream(fileLocation));
} catch (IOException e) {
System.out.println("Properties didnt load");
System.exit(0);
}
return properties;
}
private boolean isInteger(String quantityOfChars) {
try {
Integer.parseInt(quantityOfChars);
} catch (NumberFormatException e) {
return false;
}
return true;
}
}