-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpaceComplexity.java
More file actions
39 lines (34 loc) · 1.48 KB
/
Copy pathSpaceComplexity.java
File metadata and controls
39 lines (34 loc) · 1.48 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
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SpaceComplexity extends inputParser {
static int initSpaceComplexity =0;
public static double processLineInit(String wordParse){
//System.out.println(".....................Space complexity works here......................");
Pattern p1 = Pattern.compile("\\s*([^\\s]*[a-zA-Z]*)\\s*[a-zA-Z]*\\s*=\\s*\\\".*?\\\"\\s*;");//String
Pattern p2 = Pattern.compile("\\s*([^\\s]*[a-zA-Z]*)\\s*[a-zA-Z]*\\s*=\\s*\\d+\\s*;");//int
Pattern p3 = Pattern.compile("\\s*([^\\s]*[a-zA-Z]*)\\s*[a-zA-Z]*\\s*=\\s*\\d+.\\d+\\s*;");//float
Pattern p4 = Pattern.compile("\\s*([^\\s]*char)\\s*[a-zA-Z]*\\s*=\\s*[a-zA-Z]{1}\\s*;");//char
Pattern p5 = Pattern.compile("\\s*([^\\s]*boolean)\\s*[a-zA-Z]*\\s*=\\s*[tT]rue\\s*;|\\s*([^\\s]*boolean)\\s*[a-zA-Z]*\\s*=\\s*[fF]alse\\s*");//boolean
//Comparison method
Matcher m = p1.matcher(wordParse);
Matcher m1 = p2.matcher(wordParse);
Matcher m2 = p3.matcher(wordParse);
Matcher m3 = p4.matcher(wordParse);
Matcher m4 = p5.matcher(wordParse);
if(m.matches())
initSpaceComplexity += 4;
else if(m1.matches())
initSpaceComplexity += 4;
else if(m2.matches())
initSpaceComplexity += 4;
else if(m3.matches())
initSpaceComplexity += 2;
else if(m4.matches())
initSpaceComplexity += 1;
else
System.out.println();
return initSpaceComplexity;
}
}