Skip to content

Commit 29d6807

Browse files
committed
Merge remote-tracking branch 'eugenp/master'
2 parents f4f8be1 + c12ba86 commit 29d6807

234 files changed

Lines changed: 1911 additions & 1715 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-concurrency/src/main/java/com/baeldung/concurrent/blockingqueue/NumbersProducer.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ public void run() {
1919
try {
2020
generateNumbers();
2121
} catch (InterruptedException e) {
22-
Thread.currentThread().interrupt();
22+
Thread.currentThread()
23+
.interrupt();
2324
}
2425
}
2526

2627
private void generateNumbers() throws InterruptedException {
2728
for (int i = 0; i < 100; i++) {
28-
numbersQueue.put(ThreadLocalRandom.current().nextInt(100));
29+
numbersQueue.put(ThreadLocalRandom.current()
30+
.nextInt(100));
2931
}
3032
for (int j = 0; j < poisonPillPerProducer; j++) {
3133
numbersQueue.put(poisonPill);

‎core-java-concurrency/src/main/java/com/baeldung/concurrent/delayqueue/DelayObject.java‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ public int compareTo(Delayed o) {
2727

2828
@Override
2929
public String toString() {
30-
return "{" +
31-
"data='" + data + '\'' +
32-
", startTime=" + startTime +
33-
'}';
30+
return "{" + "data='" + data + '\'' + ", startTime=" + startTime + '}';
3431
}
3532
}

‎core-java-concurrency/src/test/java/com/baeldung/completablefuture/CompletableFutureLongRunningUnitTest.java‎

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class CompletableFutureLongRunningUnitTest {
1515

1616
private static final Logger LOG = LoggerFactory.getLogger(CompletableFutureLongRunningUnitTest.class);
1717

18-
1918
@Test
2019
public void whenRunningCompletableFutureAsynchronously_thenGetMethodWaitsForResult() throws InterruptedException, ExecutionException {
2120
Future<String> completableFuture = calculateAsync();
@@ -27,11 +26,12 @@ public void whenRunningCompletableFutureAsynchronously_thenGetMethodWaitsForResu
2726
private Future<String> calculateAsync() throws InterruptedException {
2827
CompletableFuture<String> completableFuture = new CompletableFuture<>();
2928

30-
Executors.newCachedThreadPool().submit(() -> {
31-
Thread.sleep(500);
32-
completableFuture.complete("Hello");
33-
return null;
34-
});
29+
Executors.newCachedThreadPool()
30+
.submit(() -> {
31+
Thread.sleep(500);
32+
completableFuture.complete("Hello");
33+
return null;
34+
});
3535

3636
return completableFuture;
3737
}
@@ -47,11 +47,12 @@ public void whenRunningCompletableFutureWithResult_thenGetMethodReturnsImmediate
4747
private Future<String> calculateAsyncWithCancellation() throws InterruptedException {
4848
CompletableFuture<String> completableFuture = new CompletableFuture<>();
4949

50-
Executors.newCachedThreadPool().submit(() -> {
51-
Thread.sleep(500);
52-
completableFuture.cancel(false);
53-
return null;
54-
});
50+
Executors.newCachedThreadPool()
51+
.submit(() -> {
52+
Thread.sleep(500);
53+
completableFuture.cancel(false);
54+
return null;
55+
});
5556

5657
return completableFuture;
5758
}
@@ -98,21 +99,24 @@ public void whenAddingThenApplyToFuture_thenFunctionExecutesAfterComputationIsFi
9899

99100
@Test
100101
public void whenUsingThenCompose_thenFuturesExecuteSequentially() throws ExecutionException, InterruptedException {
101-
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello").thenCompose(s -> CompletableFuture.supplyAsync(() -> s + " World"));
102+
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello")
103+
.thenCompose(s -> CompletableFuture.supplyAsync(() -> s + " World"));
102104

103105
assertEquals("Hello World", completableFuture.get());
104106
}
105107

106108
@Test
107109
public void whenUsingThenCombine_thenWaitForExecutionOfBothFutures() throws ExecutionException, InterruptedException {
108-
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello").thenCombine(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> s1 + s2);
110+
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello")
111+
.thenCombine(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> s1 + s2);
109112

110113
assertEquals("Hello World", completableFuture.get());
111114
}
112115

113116
@Test
114117
public void whenUsingThenAcceptBoth_thenWaitForExecutionOfBothFutures() throws ExecutionException, InterruptedException {
115-
CompletableFuture.supplyAsync(() -> "Hello").thenAcceptBoth(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> LOG.debug(s1 + s2));
118+
CompletableFuture.supplyAsync(() -> "Hello")
119+
.thenAcceptBoth(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> LOG.debug(s1 + s2));
116120
}
117121

118122
@Test
@@ -131,7 +135,9 @@ public void whenFutureCombinedWithAllOfCompletes_thenAllFuturesAreDone() throws
131135
assertTrue(future2.isDone());
132136
assertTrue(future3.isDone());
133137

134-
String combined = Stream.of(future1, future2, future3).map(CompletableFuture::join).collect(Collectors.joining(" "));
138+
String combined = Stream.of(future1, future2, future3)
139+
.map(CompletableFuture::join)
140+
.collect(Collectors.joining(" "));
135141

136142
assertEquals("Hello Beautiful World", combined);
137143
}
@@ -147,7 +153,8 @@ public void whenFutureThrows_thenHandleMethodReceivesException() throws Executio
147153
throw new RuntimeException("Computation error!");
148154
}
149155
return "Hello, " + name;
150-
}).handle((s, t) -> s != null ? s : "Hello, Stranger!");
156+
})
157+
.handle((s, t) -> s != null ? s : "Hello, Stranger!");
151158

152159
assertEquals("Hello, Stranger!", completableFuture.get());
153160
}

‎core-java-concurrency/src/test/java/com/baeldung/java/concurrentmap/ConcurrentMapAggregateStatusManualTest.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public void givenConcurrentMap_whenSizeWithoutConcurrentUpdates_thenCorrect() th
4747
executorService.awaitTermination(1, TimeUnit.MINUTES);
4848

4949
for (int i = 1; i <= MAX_SIZE; i++) {
50-
assertEquals("map size should be consistently reliable", i, mapSizes.get(i - 1).intValue());
50+
assertEquals("map size should be consistently reliable", i, mapSizes.get(i - 1)
51+
.intValue());
5152
}
5253
assertEquals(MAX_SIZE, concurrentMap.size());
5354
}
@@ -69,7 +70,8 @@ public void givenConcurrentMap_whenUpdatingAndGetSize_thenError() throws Interru
6970
executorService.shutdown();
7071
executorService.awaitTermination(1, TimeUnit.MINUTES);
7172

72-
assertNotEquals("map size collected with concurrent updates not reliable", MAX_SIZE, mapSizes.get(MAX_SIZE - 1).intValue());
73+
assertNotEquals("map size collected with concurrent updates not reliable", MAX_SIZE, mapSizes.get(MAX_SIZE - 1)
74+
.intValue());
7375
assertEquals(MAX_SIZE, concurrentMap.size());
7476
}
7577

‎core-java-concurrency/src/test/java/com/baeldung/java/concurrentmap/ConcurretMapMemoryConsistencyManualTest.java‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,38 @@ public class ConcurretMapMemoryConsistencyManualTest {
1616
public void givenConcurrentMap_whenSumParallel_thenCorrect() throws Exception {
1717
Map<String, Integer> map = new ConcurrentHashMap<>();
1818
List<Integer> sumList = parallelSum100(map, 1000);
19-
assertEquals(1, sumList.stream().distinct().count());
20-
long wrongResultCount = sumList.stream().filter(num -> num != 100).count();
19+
assertEquals(1, sumList.stream()
20+
.distinct()
21+
.count());
22+
long wrongResultCount = sumList.stream()
23+
.filter(num -> num != 100)
24+
.count();
2125
assertEquals(0, wrongResultCount);
2226
}
2327

2428
@Test
2529
public void givenHashtable_whenSumParallel_thenCorrect() throws Exception {
2630
Map<String, Integer> map = new Hashtable<>();
2731
List<Integer> sumList = parallelSum100(map, 1000);
28-
assertEquals(1, sumList.stream().distinct().count());
29-
long wrongResultCount = sumList.stream().filter(num -> num != 100).count();
32+
assertEquals(1, sumList.stream()
33+
.distinct()
34+
.count());
35+
long wrongResultCount = sumList.stream()
36+
.filter(num -> num != 100)
37+
.count();
3038
assertEquals(0, wrongResultCount);
3139
}
3240

3341
@Test
3442
public void givenHashMap_whenSumParallel_thenError() throws Exception {
3543
Map<String, Integer> map = new HashMap<>();
3644
List<Integer> sumList = parallelSum100(map, 100);
37-
assertNotEquals(1, sumList.stream().distinct().count());
38-
long wrongResultCount = sumList.stream().filter(num -> num != 100).count();
45+
assertNotEquals(1, sumList.stream()
46+
.distinct()
47+
.count());
48+
long wrongResultCount = sumList.stream()
49+
.filter(num -> num != 100)
50+
.count();
3951
assertTrue(wrongResultCount > 0);
4052
}
4153

‎core-java/src/main/java/com/baeldung/designpatterns/adapter/LuxuryCarsSpeed.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ public class LuxuryCarsSpeed {
44
public double bugattiVeyronInMPH() {
55
return 268;
66
}
7-
7+
88
public double mcLarenInMPH() {
99
return 241;
1010
}
11-
11+
1212
public double astonMartinInMPH() {
1313
return 220;
1414
}

‎core-java/src/main/java/com/baeldung/designpatterns/adapter/LuxuryCarsSpeedAdapter.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
public interface LuxuryCarsSpeedAdapter {
44
public double bugattiVeyronInKMPH();
5+
56
public double mcLarenInKMPH();
7+
68
public double astonMartinInKMPH();
79
}

‎core-java/src/main/java/com/baeldung/designpatterns/bridge/Blue.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public class Blue implements Color {
66

77
@Override
8-
public void fillColor() {
8+
public void fillColor() {
99
LOG.info("Color : Blue");
1010
}
1111

‎core-java/src/main/java/com/baeldung/designpatterns/decorator/DecoratorPatternDriver.java‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
public class DecoratorPatternDriver {
66

77
public static void main(String[] args) {
8-
//christmas tree with just one Garland
8+
// christmas tree with just one Garland
99
ChristmasTree tree1 = new Garland(new ChristmasTreeImpl());
1010
LOG.info(tree1.decorate());
11-
12-
//christmas tree with two Garlands and one Bubble lights
13-
ChristmasTree tree2 = new BubbleLights(new Garland(
14-
new Garland(new ChristmasTreeImpl()))
15-
);
11+
12+
// christmas tree with two Garlands and one Bubble lights
13+
ChristmasTree tree2 = new BubbleLights(new Garland(new Garland(new ChristmasTreeImpl())));
1614
LOG.info(tree2.decorate());
17-
15+
1816
}
1917

2018
}

‎core-java/src/main/java/com/baeldung/designpatterns/proxy/ExpensiveObjectImpl.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ public class ExpensiveObjectImpl implements ExpensiveObject {
77
public ExpensiveObjectImpl() {
88
heavyInitialConfiguration();
99
}
10-
10+
1111
@Override
1212
public void process() {
1313
LOG.info("processing complete.");
1414
}
15-
15+
1616
private void heavyInitialConfiguration() {
1717
LOG.info("Loading initial configuration...");
1818
}
19-
19+
2020
}

0 commit comments

Comments
 (0)