Skip to content

Commit aaed043

Browse files
Merge remote-tracking branch 'origin/master'
Conflicts: jsf/pom.xml
2 parents f831d98 + b72f319 commit aaed043

195 files changed

Lines changed: 6814 additions & 607 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
# Eclipse
99
.settings/
10+
*.project
11+
*.classpath
1012
.prefs
1113
*.prefs
14+
.metadata/
1215

1316
# Intellij
1417
.idea/
@@ -23,3 +26,4 @@ log/
2326
target/
2427

2528
spring-openid/src/main/resources/application.properties
29+
.recommenders/

‎core-java-8/pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
<version>3.3.2</version>
4242
</dependency>
4343

44+
<dependency>
45+
<groupId>org.slf4j</groupId>
46+
<artifactId>slf4j-api</artifactId>
47+
<version>${org.slf4j.version}</version>
48+
</dependency>
49+
4450
<!-- test scoped -->
4551

4652
<dependency>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.datetime;
2+
3+
import java.time.Duration;
4+
import java.time.LocalTime;
5+
import java.time.Period;
6+
7+
public class UseDuration {
8+
9+
public LocalTime modifyDates(LocalTime localTime,Duration duration){
10+
return localTime.plus(duration);
11+
}
12+
13+
public Duration getDifferenceBetweenDates(LocalTime localTime1,LocalTime localTime2){
14+
return Duration.between(localTime1, localTime2);
15+
}
16+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung.datetime;
2+
3+
import java.time.DayOfWeek;
4+
import java.time.LocalDate;
5+
import java.time.LocalDateTime;
6+
import java.time.temporal.ChronoUnit;
7+
import java.time.temporal.TemporalAdjusters;
8+
9+
public class UseLocalDate {
10+
11+
public LocalDate getLocalDateUsingFactoryOfMethod(int year, int month, int dayOfMonth){
12+
return LocalDate.of(year, month, dayOfMonth);
13+
}
14+
15+
public LocalDate getLocalDateUsingParseMethod(String representation){
16+
return LocalDate.parse(representation);
17+
}
18+
19+
public LocalDate getLocalDateFromClock(){
20+
LocalDate localDate = LocalDate.now();
21+
return localDate;
22+
}
23+
24+
public LocalDate getNextDay(LocalDate localDate){
25+
return localDate.plusDays(1);
26+
}
27+
28+
public LocalDate getPreviousDay(LocalDate localDate){
29+
return localDate.minus(1, ChronoUnit.DAYS);
30+
}
31+
32+
public DayOfWeek getDayOfWeek(LocalDate localDate){
33+
DayOfWeek day = localDate.getDayOfWeek();
34+
return day;
35+
}
36+
37+
public LocalDate getFirstDayOfMonth(){
38+
LocalDate firstDayOfMonth = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
39+
return firstDayOfMonth;
40+
}
41+
42+
public LocalDateTime getStartOfDay(LocalDate localDate){
43+
LocalDateTime startofDay = localDate.atStartOfDay();
44+
return startofDay;
45+
}
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.datetime;
2+
3+
import java.time.LocalDateTime;
4+
5+
public class UseLocalDateTime {
6+
7+
public LocalDateTime getLocalDateTimeUsingParseMethod(String representation){
8+
return LocalDateTime.parse(representation);
9+
}
10+
11+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.baeldung.datetime;
2+
3+
import java.time.LocalTime;
4+
import java.time.temporal.ChronoUnit;
5+
6+
public class UseLocalTime {
7+
8+
public LocalTime getLocalTimeUsingFactoryOfMethod(int hour, int min, int seconds){
9+
LocalTime localTime = LocalTime.of(hour, min, seconds);
10+
return localTime;
11+
}
12+
13+
public LocalTime getLocalTimeUsingParseMethod(String timeRepresentation){
14+
LocalTime localTime = LocalTime.parse(timeRepresentation);
15+
return localTime;
16+
}
17+
18+
public LocalTime getLocalTimeFromClock(){
19+
LocalTime localTime = LocalTime.now();
20+
return localTime;
21+
}
22+
23+
public LocalTime addAnHour(LocalTime localTime){
24+
LocalTime newTime = localTime.plus(1,ChronoUnit.HOURS);
25+
return newTime;
26+
}
27+
28+
public int getHourFromLocalTime(LocalTime localTime){
29+
return localTime.getHour();
30+
}
31+
32+
public LocalTime getLocalTimeWithMinuteSetToValue(LocalTime localTime, int minute){
33+
return localTime.withMinute(minute);
34+
}
35+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.datetime;
2+
3+
import java.time.LocalDate;
4+
import java.time.Period;
5+
6+
public class UsePeriod {
7+
8+
public LocalDate modifyDates(LocalDate localDate,Period period){
9+
return localDate.plus(period);
10+
}
11+
12+
public Period getDifferenceBetweenDates(LocalDate localDate1,LocalDate localDate2){
13+
return Period.between(localDate1, localDate2);
14+
}
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.datetime;
2+
3+
import java.time.LocalDateTime;
4+
import java.time.ZoneId;
5+
import java.util.Calendar;
6+
import java.util.Date;
7+
8+
public class UseToInstant {
9+
10+
public LocalDateTime convertDateToLocalDate(Date date){
11+
LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
12+
return localDateTime;
13+
}
14+
15+
public LocalDateTime convertDateToLocalDate(Calendar calendar){
16+
LocalDateTime localDateTime = LocalDateTime.ofInstant(calendar.toInstant(), ZoneId.systemDefault());
17+
return localDateTime;
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.datetime;
2+
3+
import java.time.LocalDateTime;
4+
import java.time.ZoneId;
5+
import java.time.ZonedDateTime;
6+
7+
public class UseZonedDateTime {
8+
9+
public ZonedDateTime getZonedDateTime(LocalDateTime localDateTime,ZoneId zoneId){
10+
ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, zoneId);
11+
return zonedDateTime;
12+
}
13+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.baeldung.enums;
2+
3+
import java.util.EnumMap;
4+
import java.util.EnumSet;
5+
import java.util.List;
6+
import java.util.stream.Collectors;
7+
8+
public class Pizza {
9+
10+
private static EnumSet<PizzaStatusEnum> deliveredPizzaStatuses =
11+
EnumSet.of(PizzaStatusEnum.DELIVERED);
12+
13+
private PizzaStatusEnum status;
14+
15+
public enum PizzaStatusEnum {
16+
ORDERED(5) {
17+
@Override
18+
public boolean isOrdered() {
19+
return true;
20+
}
21+
},
22+
READY(2) {
23+
@Override
24+
public boolean isReady() {
25+
return true;
26+
}
27+
},
28+
DELIVERED(0) {
29+
@Override
30+
public boolean isDelivered() {
31+
return true;
32+
}
33+
};
34+
35+
private int timeToDelivery;
36+
37+
public boolean isOrdered() {
38+
return false;
39+
}
40+
41+
public boolean isReady() {
42+
return false;
43+
}
44+
45+
public boolean isDelivered() {
46+
return false;
47+
}
48+
49+
public int getTimeToDelivery() {
50+
return timeToDelivery;
51+
}
52+
53+
PizzaStatusEnum(int timeToDelivery) {
54+
this.timeToDelivery = timeToDelivery;
55+
}
56+
}
57+
58+
public PizzaStatusEnum getStatus() {
59+
return status;
60+
}
61+
62+
public void setStatus(PizzaStatusEnum status) {
63+
this.status = status;
64+
}
65+
66+
public boolean isDeliverable() {
67+
return this.status.isReady();
68+
}
69+
70+
public void printTimeToDeliver() {
71+
System.out.println("Time to delivery is " + this.getStatus().getTimeToDelivery() + " days");
72+
}
73+
74+
public static List<Pizza> getAllUndeliveredPizzas(List<Pizza> input) {
75+
return input.stream().filter((s) -> !deliveredPizzaStatuses.contains(s.getStatus())).collect(Collectors.toList());
76+
}
77+
78+
public static EnumMap<PizzaStatusEnum, List<Pizza>> groupPizzaByStatus(List<Pizza> pzList) {
79+
return pzList.stream().collect(
80+
Collectors.groupingBy(Pizza::getStatus,
81+
() -> new EnumMap<>(PizzaStatusEnum.class), Collectors.toList()));
82+
}
83+
84+
public void deliver() {
85+
if (isDeliverable()) {
86+
PizzaDeliverySystemConfiguration.getInstance().getDeliveryStrategy().deliver(this);
87+
this.setStatus(PizzaStatusEnum.DELIVERED);
88+
}
89+
}
90+
91+
}

0 commit comments

Comments
 (0)