Skip to content

Commit dbff14e

Browse files
committed
2 parents e85b550 + eb324fc commit dbff14e

File tree

10 files changed

+449
-42
lines changed

10 files changed

+449
-42
lines changed

core-java/jdbc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Manifest-Version: 1.0
2-
Built-By: Admin
3-
Build-Jdk: 1.8.0_231
2+
Built-By: vn
3+
Build-Jdk: 1.8.0_251
44
Created-By: Maven Integration for Eclipse
55

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Generated by Maven Integration for Eclipse
2-
#Wed Jun 10 07:29:23 IST 2020
2+
#Sat Jun 13 20:31:42 EDT 2020
33
version=0.0.1-SNAPSHOT
44
groupId=com.lwl
55
m2e.projectName=jdbc
6-
m2e.projectLocation=C\:\\Users\\Admin\\Desktop\\fs_batch_3\\jdbc
6+
m2e.projectLocation=D\:\\GIT\\java_full_stack_b_2\\core-java\\jdbc
77
artifactId=jdbc

junit5/pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,28 @@
2222
<version>${junit.jupiter.version}</version>
2323
<scope>test</scope>
2424
</dependency>
25+
<dependency>
26+
<groupId>mysql</groupId>
27+
<artifactId>mysql-connector-java</artifactId>
28+
<version>8.0.14</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.fasterxml.jackson.core</groupId>
32+
<artifactId>jackson-databind</artifactId>
33+
<version>2.11.0</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.zaxxer</groupId>
37+
<artifactId>HikariCP</artifactId>
38+
<version>3.4.5</version>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.projectlombok</groupId>
43+
<artifactId>lombok</artifactId>
44+
<version>1.18.6</version>
45+
<scope>provided</scope>
46+
</dependency>
2547
</dependencies>
2648

2749
<build>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.lwl.junit;
2+
3+
import java.io.File;
4+
import java.io.FileNotFoundException;
5+
import java.io.IOException;
6+
import java.nio.file.Paths;
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
import java.util.Scanner;
10+
11+
import com.fasterxml.jackson.core.JsonParseException;
12+
import com.fasterxml.jackson.databind.JsonMappingException;
13+
14+
public class CSVManager<T> {
15+
16+
private String filename;
17+
//private List<T> list = new ArrayList<T>();
18+
private List<CourseData> list = new ArrayList<CourseData>();
19+
20+
public CSVManager(String filename) {
21+
this.filename = filename;
22+
T t = null;
23+
Scanner sc;
24+
try {
25+
sc = new Scanner(new File(filename));
26+
//sc.useDelimiter(",");
27+
sc.nextLine(); // to skip headers
28+
while (sc.hasNextLine()) {
29+
String string = sc.nextLine();
30+
String splitstr[] = string.split(",");
31+
/* need to make it generic ??
32+
* if ( T.class == CourseData ) {
33+
*
34+
* } t = new T (splitstr[0], splitstr[1],splitstr[2],splitstr[3],splitstr[4],
35+
* Double.parseDouble(splitstr[5]));
36+
*/
37+
CourseData cd = new CourseData(splitstr[0], splitstr[1], splitstr[2], splitstr[3], splitstr[4], Double.parseDouble(splitstr[5]));
38+
list.add(cd);
39+
40+
}
41+
sc.close();
42+
} catch (IOException e) {
43+
e.printStackTrace();
44+
}
45+
46+
}
47+
48+
public String getFilename() {
49+
return filename;
50+
}
51+
52+
public List<CourseData> getList() {
53+
return list;
54+
}
55+
56+
57+
58+
/*
59+
* public static void main(String[] args) { CSVManager csvm = new
60+
* CSVManager<CourseData>("src/main/resources/coursedata.csv"); }
61+
*/
62+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.lwl.junit;
2+
3+
import lombok.*;
4+
5+
@AllArgsConstructor
6+
@Getter
7+
@Setter
8+
@ToString
9+
10+
// *** This class holds the course data **
11+
12+
public class CourseData {
13+
private String Name;
14+
private String Batch;
15+
private String Completed;
16+
private String Placed;
17+
private String Degree;
18+
private Double Score;
19+
20+
21+
22+
23+
24+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package com.lwl.junit;
2+
3+
import java.util.HashMap;
4+
import java.util.List;
5+
import java.util.Map;
6+
import java.util.function.Predicate;
7+
import java.util.stream.Collectors;
8+
9+
10+
public class CourseDataManager {
11+
private static List<CourseData> cdArray;
12+
13+
14+
{
15+
CSVManager<CourseData> csvm = new CSVManager<CourseData>("src/main/resources/coursedata.csv");
16+
cdArray = csvm.getList();
17+
}
18+
19+
20+
void StudentQualBEMCABSCtest() {
21+
System.out.println("-----------------------------------------------------------------------------------------------------");
22+
System.out.println("StudentQualBEMCABSCtest");
23+
Predicate<CourseData> pd = (c -> (c.getDegree().equalsIgnoreCase("BE") || c.getDegree().equalsIgnoreCase("MCA")
24+
|| c.getDegree().equalsIgnoreCase("BSC")));
25+
26+
cdArray.stream().filter(pd).forEach(System.out::println);
27+
}
28+
29+
30+
void StudentCountBEtest() {
31+
System.out.println("-----------------------------------------------------------------------------------------------------");
32+
System.out.println("StudentCountBEtest");
33+
Predicate<CourseData> pd = (c -> (c.getDegree().equalsIgnoreCase("BE")));
34+
35+
long count = cdArray.stream().filter(pd).count();
36+
System.out.println("Count of BE Students is :" + count);
37+
}
38+
39+
40+
void StudentCountPlaced() {
41+
System.out.println("-----------------------------------------------------------------------------------------------------");
42+
System.out.println("StudentCountPlaced");
43+
Predicate<CourseData> pd = (c -> (c.getPlaced().equalsIgnoreCase("Y")));
44+
45+
long count = cdArray.stream().filter(pd).count();
46+
System.out.println("Count of Number of Students Placed is :" + count);
47+
}
48+
49+
50+
void StudentCountCompletedButNotPlaced() {
51+
System.out.println("-----------------------------------------------------------------------------------------------------");
52+
System.out.println("StudentCountCompletedButNotPlaced");
53+
Predicate<CourseData> pd = (c -> (c.getCompleted().equalsIgnoreCase("Y") && !c.getPlaced().equalsIgnoreCase("Y")));
54+
55+
long count = cdArray.stream().filter(pd).count();
56+
System.out.println("Count of Number of Students Who Completed Course But Not Placed is :" + count);
57+
}
58+
59+
60+
void StudentCountNotPlacedAndPlaced() {
61+
System.out.println("-----------------------------------------------------------------------------------------------------");
62+
System.out.println("StudentCountNotPlacedAndPlaced");
63+
Predicate<CourseData> pd = (c -> (c.getPlaced().equalsIgnoreCase("Y")));
64+
Predicate<CourseData> pd1 = (c -> (!c.getPlaced().equalsIgnoreCase("Y")));
65+
66+
long count = cdArray.stream().filter(pd).count();
67+
System.out.println("Count of Number of Students Placed is :" + count);
68+
long count1 = cdArray.stream().filter(pd1).count();
69+
70+
System.out.println("Count of Number of Students NOT Placed is :" + count1);
71+
}
72+
73+
74+
void StudentByName() {
75+
System.out.println("-----------------------------------------------------------------------------------------------------");
76+
System.out.println("StudentSearchByName" + "CLARK");
77+
Predicate<CourseData> pd = (c -> (c.getName().contains("CLARK") ));
78+
79+
cdArray.stream().filter(pd).forEach(System.out::println);
80+
long count = cdArray.stream().filter(pd).count();
81+
System.out.println("Count of Number of Students Who Completed Course But Not Placed is :" + count);
82+
}
83+
84+
85+
86+
void StudentNames() {
87+
System.out.println("-----------------------------------------------------------------------------------------------------");
88+
System.out.println("StudentNames" );
89+
90+
for (CourseData ele : cdArray) {
91+
System.out.println(ele.getName());
92+
}
93+
94+
}
95+
96+
97+
void StudentQualAndCount() {
98+
System.out.println("-----------------------------------------------------------------------------------------------------");
99+
System.out.println("StudentQualAndCount" );
100+
Map<String, Long> qualCount = new HashMap<String, Long>();
101+
qualCount = cdArray.stream().collect(Collectors.groupingBy(CourseData::getDegree, Collectors.counting()));
102+
System.out.println(qualCount);
103+
104+
}
105+
106+
107+
108+
void StudentQualAndScoreInRange() {
109+
System.out.println("-----------------------------------------------------------------------------------------------------");
110+
System.out.println("StudentQualAndScoreInRange" );
111+
int lower_range = 80;
112+
int higher_range = 90;
113+
114+
Predicate<CourseData> pd = (c -> (c.getDegree().equalsIgnoreCase("BE") && c.getScore() >= lower_range && c.getScore() <= higher_range ));
115+
116+
long count = cdArray.stream().filter(pd).count();
117+
System.out.println("Count of BE Students Who Scored Between 80 and 90 Percent Is :" + count + " out of " + cdArray.stream().count());
118+
119+
}
120+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.lwl.junit;
2+
3+
import java.io.File;
4+
import java.io.FileNotFoundException;
5+
import java.io.IOException;
6+
7+
import com.fasterxml.jackson.core.JsonParseException;
8+
import com.fasterxml.jackson.databind.JsonMappingException;
9+
import com.fasterxml.jackson.databind.ObjectMapper;
10+
11+
public class JSONManager {
12+
private ObjectMapper om;
13+
14+
{
15+
this.om = new ObjectMapper();
16+
}
17+
18+
public <T> T LoadGenericJson(Class<T> obj, String filename) throws FileNotFoundException {
19+
File fs = new File(filename);
20+
try {
21+
return om.readValue(fs, obj);
22+
// JavaType type = om.getTypeFactory().constructParametricType(obj.class, obj);
23+
// return om.readValue(fs, new TypeReference<T>() {});
24+
25+
} catch (JsonParseException e1) {
26+
e1.printStackTrace();
27+
} catch (JsonMappingException e1) {
28+
e1.printStackTrace();
29+
} catch (IOException e1) {
30+
e1.printStackTrace();
31+
}
32+
33+
return null;
34+
}
35+
}

0 commit comments

Comments
 (0)