Skip to content

Commit a39f37d

Browse files
committed
完成所有代码的更新和提交
1 parent 02546c1 commit a39f37d

15 files changed

Lines changed: 392 additions & 0 deletions

File tree

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.ossez.anonymousclass;
2+
3+
public class EmailSenderService implements SenderService {
4+
5+
@Override
6+
public String callSender(Sender sender) {
7+
return sender.send("Email Notification");
8+
}
9+
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.ossez.anonymousclass;
2+
3+
public interface Sender {
4+
5+
String send(final String message);
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.ossez.anonymousclass;
2+
3+
public interface SenderService {
4+
5+
String callSender(Sender sender);
6+
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.ossez.anonymousclass;
2+
3+
public class SmsSenderService implements SenderService {
4+
5+
@Override
6+
public String callSender(Sender sender) {
7+
return sender.send("SMS Notification");
8+
}
9+
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.ossez.java8.lambda.serialization;
2+
3+
import java.io.Serializable;
4+
5+
public class SerializableLambdaExpression {
6+
public static Object getLambdaExpressionObject() {
7+
Runnable r = (Runnable & Serializable) () -> System.out.println("please serialize this message");
8+
return r;
9+
}
10+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.ossez.suppliercallable.data;
2+
3+
import java.time.LocalDate;
4+
5+
public class User {
6+
7+
private String name;
8+
private String surname;
9+
private LocalDate birthDate;
10+
private Integer age;
11+
private Boolean canDriveACar = false;
12+
13+
public User(String name, String surname, LocalDate birthDate) {
14+
this.name = name;
15+
this.surname = surname;
16+
this.birthDate = birthDate;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
23+
public void setName(String name) {
24+
this.name = name;
25+
}
26+
27+
public String getSurname() {
28+
return surname;
29+
}
30+
31+
public void setSurname(String surname) {
32+
this.surname = surname;
33+
}
34+
35+
public LocalDate getBirthDate() {
36+
return birthDate;
37+
}
38+
39+
public void setBirthDate(LocalDate birthDate) {
40+
this.birthDate = birthDate;
41+
}
42+
43+
public void setAge(Integer age) {
44+
this.age = age;
45+
}
46+
47+
public Integer getAge() {
48+
return age;
49+
}
50+
51+
public Boolean getCanDriveACar() {
52+
return canDriveACar;
53+
}
54+
55+
public void setCanDriveACar(Boolean canDriveACar) {
56+
this.canDriveACar = canDriveACar;
57+
}
58+
59+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.ossez.suppliercallable.service;
2+
3+
import com.ossez.suppliercallable.data.User;
4+
5+
public interface Service {
6+
7+
User execute(User user);
8+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.ossez.suppliercallable.service.callable;
2+
3+
import java.time.LocalDate;
4+
import java.time.Period;
5+
import java.util.concurrent.Callable;
6+
7+
public class AgeCalculatorCallable implements Callable<Integer> {
8+
9+
private final LocalDate birthDate;
10+
11+
@Override
12+
public Integer call() throws Exception {
13+
return Period.between(birthDate, LocalDate.now())
14+
.getYears();
15+
}
16+
17+
public AgeCalculatorCallable(LocalDate birthDate) {
18+
this.birthDate = birthDate;
19+
}
20+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.ossez.suppliercallable.service.callable;
2+
3+
import java.util.concurrent.ExecutionException;
4+
import java.util.concurrent.ExecutorService;
5+
import java.util.concurrent.Executors;
6+
import java.util.concurrent.Future;
7+
8+
import com.ossez.suppliercallable.data.User;
9+
import com.ossez.suppliercallable.service.Service;
10+
11+
public class CallableServiceImpl implements Service {
12+
13+
@Override
14+
public User execute(User user) {
15+
ExecutorService executorService = Executors.newCachedThreadPool();
16+
17+
try {
18+
Future<Integer> ageFuture = executorService.submit(new AgeCalculatorCallable(user.getBirthDate()));
19+
Integer age = ageFuture.get();
20+
Future<Boolean> canDriveACarFuture = executorService.submit(new CarDriverValidatorCallable(age));
21+
Boolean canDriveACar = canDriveACarFuture.get();
22+
user.setAge(age);
23+
user.setCanDriveACar(canDriveACar);
24+
} catch (ExecutionException | InterruptedException e) {
25+
throw new RuntimeException(e.getCause());
26+
}
27+
28+
return user;
29+
}
30+
31+
}

0 commit comments

Comments
 (0)