-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
93 lines (77 loc) · 2.01 KB
/
Test.java
File metadata and controls
93 lines (77 loc) · 2.01 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
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author JC
*/
public class Test {
private static String getRandomString( Set<String> stringSet)
{
Random rand = new Random();
int rand_index = 0;
if(stringSet.size() > 0)
{
rand_index = rand.nextInt(stringSet.size());
}
for(String string : stringSet)
{
--rand_index;
if(rand_index == 0)
{
return string;
}
}
return null;
}
private static Character getRandomChar()
{
Random rand = new Random();
String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int rand_char_index = rand.nextInt(alphabet.length() - 1);
return alphabet.charAt(rand_char_index);
}
public static void printDetails(String s, String regex, int maxSize)
{
boolean sizeGood = false;
System.out.print(s);
System.out.print(" : ");
System.out.println(s.matches(regex));
if(s.length() <= maxSize) sizeGood = true;
else sizeGood = false;
System.out.println("Size: " + sizeGood);
}
public static void TestRegex(String regex, Set<String> stringSet, int maxSize, boolean printAll)
{
if(printAll)
{
System.out.println("Checking original set.");
for(String string : stringSet)
{
printDetails(string, regex, maxSize);
}
}
else
{
System.out.println("Checking original set.");
for(String string : stringSet)
{
if(!string.matches(regex))
{
System.out.println(string + " does not match regex!");
}
if(string.length() > maxSize)
{
System.out.println(string + "length " + string.length() + " is greater than " + maxSize);
}
}
}
}
}