Skip to content

Commit fa8dee2

Browse files
author
Dassi Orleando
committed
Merge branch 'master' of https://github.com/eugenp/tutorials
2 parents dc18980 + 546cc07 commit fa8dee2

197 files changed

Lines changed: 33549 additions & 1093 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.

‎core-java-8/src/main/java/com/baeldung/datetime/UseDuration.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.time.Duration;
44
import java.time.LocalTime;
5-
import java.time.Period;
65

76
public class UseDuration {
87

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.defaultstaticinterfacemethods.application;
2+
3+
import com.baeldung.defaultstaticinterfacemethods.model.Car;
4+
import com.baeldung.defaultstaticinterfacemethods.model.Vehicle;
5+
6+
public class Application {
7+
8+
public static void main(String[] args) {
9+
10+
Vehicle car = new Car("BMW");
11+
System.out.println(car.getBrand());
12+
System.out.println(car.speedUp());
13+
System.out.println(car.slowDown());
14+
System.out.println(car.turnAlarmOn());
15+
System.out.println(car.turnAlarmOff());
16+
System.out.println(Vehicle.getHorsePower(2500, 480));
17+
}
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.defaultstaticinterfacemethods.model;
2+
3+
public interface Alarm {
4+
5+
default String turnAlarmOn() {
6+
return "Turning the alarm on.";
7+
}
8+
9+
default String turnAlarmOff() {
10+
return "Turning the alarm off.";
11+
}
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.defaultstaticinterfacemethods.model;
2+
3+
public class Car implements Vehicle {
4+
5+
private final String brand;
6+
7+
public Car(String brand) {
8+
this.brand = brand;
9+
}
10+
11+
@Override
12+
public String getBrand() {
13+
return brand;
14+
}
15+
16+
@Override
17+
public String speedUp() {
18+
return "The car is speeding up.";
19+
}
20+
21+
@Override
22+
public String slowDown() {
23+
return "The car is slowing down.";
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.defaultstaticinterfacemethods.model;
2+
3+
public class Motorbike implements Vehicle {
4+
5+
private final String brand;
6+
7+
public Motorbike(String brand) {
8+
this.brand = brand;
9+
}
10+
11+
@Override
12+
public String getBrand() {
13+
return brand;
14+
}
15+
16+
@Override
17+
public String speedUp() {
18+
return "The motorbike is speeding up.";
19+
}
20+
21+
@Override
22+
public String slowDown() {
23+
return "The motorbike is slowing down.";
24+
}
25+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.baeldung.defaultstaticinterfacemethods.model;
2+
3+
public class MultiAlarmCar implements Vehicle, Alarm {
4+
5+
private final String brand;
6+
7+
public MultiAlarmCar(String brand) {
8+
this.brand = brand;
9+
}
10+
11+
@Override
12+
public String getBrand() {
13+
return brand;
14+
}
15+
16+
@Override
17+
public String speedUp() {
18+
return "The motorbike is speeding up.";
19+
}
20+
21+
@Override
22+
public String slowDown() {
23+
return "The mootorbike is slowing down.";
24+
}
25+
26+
@Override
27+
public String turnAlarmOn() {
28+
return Vehicle.super.turnAlarmOn() + " " + Alarm.super.turnAlarmOn();
29+
}
30+
31+
@Override
32+
public String turnAlarmOff() {
33+
return Vehicle.super.turnAlarmOff() + " " + Alarm.super.turnAlarmOff();
34+
}
35+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.defaultstaticinterfacemethods.model;
2+
3+
public interface Vehicle {
4+
5+
String getBrand();
6+
7+
String speedUp();
8+
9+
String slowDown();
10+
11+
default String turnAlarmOn() {
12+
return "Turning the vehice alarm on.";
13+
}
14+
15+
default String turnAlarmOff() {
16+
return "Turning the vehicle alarm off.";
17+
}
18+
19+
static int getHorsePower(int rpm, int torque) {
20+
return (rpm * torque) / 5252;
21+
}
22+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.baeldung.iterators;
2+
3+
import java.util.ArrayList;
4+
import java.util.Iterator;
5+
import java.util.concurrent.ConcurrentHashMap;
6+
7+
/**
8+
* Source code https://github.com/eugenp/tutorials
9+
*
10+
* @author Santosh Thakur
11+
*/
12+
13+
public class Iterators {
14+
15+
public static int failFast1() {
16+
ArrayList<Integer> numbers = new ArrayList<>();
17+
18+
numbers.add(10);
19+
numbers.add(20);
20+
numbers.add(30);
21+
numbers.add(40);
22+
23+
Iterator<Integer> iterator = numbers.iterator();
24+
while (iterator.hasNext()) {
25+
Integer number = iterator.next();
26+
numbers.add(50);
27+
}
28+
29+
return numbers.size();
30+
}
31+
32+
public static int failFast2() {
33+
ArrayList<Integer> numbers = new ArrayList<>();
34+
numbers.add(10);
35+
numbers.add(20);
36+
numbers.add(30);
37+
numbers.add(40);
38+
39+
Iterator<Integer> iterator = numbers.iterator();
40+
while (iterator.hasNext()) {
41+
if (iterator.next() == 30) {
42+
// will not throw Exception
43+
iterator.remove();
44+
}
45+
}
46+
47+
System.out.println("using iterator's remove method = " + numbers);
48+
49+
iterator = numbers.iterator();
50+
while (iterator.hasNext()) {
51+
if (iterator.next() == 40) {
52+
// will throw Exception on
53+
// next call of next() method
54+
numbers.remove(2);
55+
}
56+
}
57+
58+
return numbers.size();
59+
}
60+
61+
public static int failSafe1() {
62+
ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<>();
63+
64+
map.put("First", 10);
65+
map.put("Second", 20);
66+
map.put("Third", 30);
67+
map.put("Fourth", 40);
68+
69+
Iterator<String> iterator = map.keySet()
70+
.iterator();
71+
72+
while (iterator.hasNext()) {
73+
String key = iterator.next();
74+
map.put("Fifth", 50);
75+
}
76+
77+
return map.size();
78+
}
79+
80+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.stream;
2+
3+
import java.util.Arrays;
4+
import java.util.stream.IntStream;
5+
6+
class PrimitiveStreams {
7+
8+
int min(int[] integers) {
9+
return Arrays.stream(integers).min().getAsInt();
10+
}
11+
12+
int max(int... integers) {
13+
return IntStream.of(integers).max().getAsInt();
14+
}
15+
16+
int sum(int... integers) {
17+
return IntStream.of(integers).sum();
18+
}
19+
20+
double avg(int... integers) {
21+
return IntStream.of(integers).average().getAsDouble();
22+
}
23+
}

‎core-java-8/src/main/java/com/baeldung/streamApi/Product.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.baeldung.streamApi;
22

33
import java.util.List;
4-
import java.util.Optional;
5-
import java.util.stream.IntStream;
64
import java.util.stream.Stream;
75

86
/**

0 commit comments

Comments
 (0)