Skip to content

Commit 8be05e8

Browse files
author
Arun-Janani
committed
LocalDate sample Snippet
1 parent 32e487f commit 8be05e8

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

java8/src/com/domain/Employee.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.domain;
22

3+
import java.util.Date;
34
import java.util.StringJoiner;
45

6+
57
public class Employee implements Comparable<Employee>{
68
//public class Employee {
79

@@ -19,6 +21,8 @@ public class Employee implements Comparable<Employee>{
1921
private String sex;
2022

2123
private Integer age;
24+
25+
private Date date_of_birth;
2226

2327
public String getId() {
2428
return id;
@@ -75,7 +79,15 @@ public void setAge(Integer age) {
7579
this.age = age;
7680
}
7781

78-
@Override
82+
public Date getDate_of_birth() {
83+
return date_of_birth;
84+
}
85+
86+
public void setDate_of_birth(Date date_of_birth) {
87+
this.date_of_birth = date_of_birth;
88+
}
89+
90+
@Override
7991
public String toString() {
8092
StringJoiner sj = new StringJoiner(",","{","}");
8193
sj.add("id: ").add(this.id).add("firstName : ").add(this.first_Name).

java8/src/com/domain/EmployeeFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static List<Employee> getEmployeeList() {
3939
e3.setPhone_Number("+91 9600328267");
4040
e3.setEmp_type(EmployeeType.Temporary.toString());
4141
e3.setSex(SexType.Male.toString());
42-
e3.setAge(30);
42+
e3.setAge(28);
4343

4444
employeeList.add(e3);
4545

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.lambdas;
2+
3+
import java.time.Instant;
4+
import java.time.LocalDate;
5+
import java.time.LocalDateTime;
6+
import java.time.Period;
7+
import java.time.temporal.TemporalAccessor;
8+
import java.util.Date;
9+
10+
public class SampleDateAPI {
11+
12+
public static void main(String[] args) {
13+
14+
Instant i = Instant.now();
15+
16+
System.out.println("Time now from Instant API "+i);
17+
//Time now 2019-06-29T09:52:03.688Z
18+
19+
LocalDate localDate = LocalDate.now();
20+
System.out.println("Time now from LocalDate API " +localDate);
21+
//2019-06-29
22+
23+
LocalDateTime localDateTime = LocalDateTime.now();
24+
System.out.println("Time now from localDateTime API " +localDateTime);
25+
//2019-06-29T15:33:40.774
26+
27+
28+
/** Age Calculator
29+
*
30+
*/
31+
getAge();
32+
33+
}
34+
35+
public static void getAge() {
36+
LocalDate localDate = LocalDate.of(1990, 7, 19);
37+
//System.out.println(localDate.;
38+
Period period = Period.between(LocalDate.now(), localDate);
39+
System.out.println("how old are you ?" + period.getYears());
40+
}
41+
42+
43+
44+
}

java8/src/com/lambdas/SampleLambdas.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ public static void main(String[] args) {
146146
/**
147147
* {28=[Arunprasad], 45=[Janani], 29=[Prasad], 30=[Kumar]}
148148
*/
149+
150+
//getting Employee Names based on age greater then 25
151+
Map<Integer,String> e3 =
152+
employees.stream().filter(EmployeePredicate.getAgePrediate(25)).
153+
collect(
154+
Collectors.groupingBy(
155+
Employee::getAge,
156+
Collectors.mapping(
157+
Employee::getFirst_Name,
158+
Collectors.joining(",","(",")")
159+
)
160+
)
161+
);
162+
System.out.println(e3);
149163
System.out.println("---------Group by End-----------");
150164

151165
}

0 commit comments

Comments
 (0)