Skip to content

Commit 147e2e6

Browse files
Ap284aparna
and
aparna
authored
feature: added code refactoring changes for 2378 (iluwatar#2379)
* fix:added code refactoring changes for 2378 * fix:added code refactoring changes for 2378 * build fix for 2378 * fix: updated pom.xml files for 2378 issue * fix:build fix for 2378 issue Co-authored-by: aparna <[email protected]>
1 parent 6693527 commit 147e2e6

File tree

32 files changed

+202
-134
lines changed

32 files changed

+202
-134
lines changed

collecting-parameter/pom.xml

-26
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!--
3-
4-
This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
5-
6-
The MIT License
7-
Copyright © 2014-2022 Ilkka Seppälä
8-
9-
Permission is hereby granted, free of charge, to any person obtaining a copy
10-
of this software and associated documentation files (the "Software"), to deal
11-
in the Software without restriction, including without limitation the rights
12-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13-
copies of the Software, and to permit persons to whom the Software is
14-
furnished to do so, subject to the following conditions:
15-
16-
The above copyright notice and this permission notice shall be included in
17-
all copies or substantial portions of the Software.
18-
19-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25-
THE SOFTWARE.
26-
27-
-->
282
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
293
<parent>
304
<artifactId>java-design-patterns</artifactId>

collecting-parameter/src/main/java/com/iluwatar/collectingparameter/App.java

-24
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
/*
2-
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
3-
*
4-
* The MIT License
5-
* Copyright © 2014-2022 Ilkka Seppälä
6-
*
7-
* Permission is hereby granted, free of charge, to any person obtaining a copy
8-
* of this software and associated documentation files (the "Software"), to deal
9-
* in the Software without restriction, including without limitation the rights
10-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
* copies of the Software, and to permit persons to whom the Software is
12-
* furnished to do so, subject to the following conditions:
13-
*
14-
* The above copyright notice and this permission notice shall be included in
15-
* all copies or substantial portions of the Software.
16-
*
17-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23-
* THE SOFTWARE.
24-
*/
251
package com.iluwatar.collectingparameter;
262

273
import java.util.LinkedList;

collecting-parameter/src/main/java/com/iluwatar/collectingparameter/PrinterItem.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ public PrinterItem(PaperSizes paperSize, int pageCount, boolean isDoubleSided, b
3131
this.isDoubleSided = isDoubleSided;
3232

3333
}
34-
}
34+
}

collecting-parameter/src/test/java/com/iluwatar/collectingparameter/AppTest.java

-24
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
/*
2-
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
3-
*
4-
* The MIT License
5-
* Copyright © 2014-2022 Ilkka Seppälä
6-
*
7-
* Permission is hereby granted, free of charge, to any person obtaining a copy
8-
* of this software and associated documentation files (the "Software"), to deal
9-
* in the Software without restriction, including without limitation the rights
10-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
* copies of the Software, and to permit persons to whom the Software is
12-
* furnished to do so, subject to the following conditions:
13-
*
14-
* The above copyright notice and this permission notice shall be included in
15-
* all copies or substantial portions of the Software.
16-
*
17-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23-
* THE SOFTWARE.
24-
*/
251
package com.iluwatar.collectingparameter;
262

273
import org.junit.jupiter.api.Test;

collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/FunctionalProgramming.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private FunctionalProgramming() {
5656
public static List<String> getModelsAfter2000(List<Car> cars) {
5757
return cars.stream().filter(car -> car.getYear() > 2000)
5858
.sorted(Comparator.comparing(Car::getYear))
59-
.map(Car::getModel).collect(Collectors.toList());
59+
.map(Car::getModel).toList();
6060
}
6161

6262
/**
@@ -78,6 +78,6 @@ public static Map<Category, List<Car>> getGroupingOfCarsByCategory(List<Car> car
7878
public static List<Car> getSedanCarsOwnedSortedByDate(List<Person> persons) {
7979
return persons.stream().map(Person::getCars).flatMap(List::stream)
8080
.filter(car -> Category.SEDAN.equals(car.getCategory()))
81-
.sorted(Comparator.comparing(Car::getYear)).collect(Collectors.toList());
81+
.sorted(Comparator.comparing(Car::getYear)).toList();
8282
}
8383
}

combinator/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
-->
2828
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2929
<modelVersion>4.0.0</modelVersion>
30-
<parent>
30+
<parent>
3131
<groupId>com.iluwatar</groupId>
3232
<artifactId>java-design-patterns</artifactId>
3333
<version>1.26.0-SNAPSHOT</version>

converter/src/main/java/com/iluwatar/converter/Converter.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.Collection;
2828
import java.util.List;
2929
import java.util.function.Function;
30-
import java.util.stream.Collectors;
3130
import lombok.RequiredArgsConstructor;
3231

3332
/**
@@ -74,7 +73,7 @@ public final T convertFromEntity(final U entity) {
7473
* with the conversion function
7574
*/
7675
public final List<U> createFromDtos(final Collection<T> dtos) {
77-
return dtos.stream().map(this::convertFromDto).collect(Collectors.toList());
76+
return dtos.stream().map(this::convertFromDto).toList();
7877
}
7978

8079
/**
@@ -85,7 +84,7 @@ public final List<U> createFromDtos(final Collection<T> dtos) {
8584
* with the conversion function
8685
*/
8786
public final List<T> createFromEntities(final Collection<U> entities) {
88-
return entities.stream().map(this::convertFromEntity).collect(Collectors.toList());
87+
return entities.stream().map(this::convertFromEntity).toList();
8988
}
9089

9190
}

data-transfer-object/src/main/java/com/iluwatar/datatransfer/product/ProductResource.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
package com.iluwatar.datatransfer.product;
2626

2727
import java.util.List;
28-
import java.util.stream.Collectors;
2928

3029
/**
3130
* The resource class which serves product information. This class act as server in the demo. Which
@@ -54,7 +53,7 @@ public List<ProductDto.Response.Private> getAllProductsForAdmin() {
5453
.map(p -> new ProductDto.Response.Private().setId(p.getId()).setName(p.getName())
5554
.setCost(p.getCost())
5655
.setPrice(p.getPrice()))
57-
.collect(Collectors.toList());
56+
.toList();
5857
}
5958

6059
/**
@@ -67,7 +66,7 @@ public List<ProductDto.Response.Public> getAllProductsForCustomer() {
6766
.stream()
6867
.map(p -> new ProductDto.Response.Public().setId(p.getId()).setName(p.getName())
6968
.setPrice(p.getPrice()))
70-
.collect(Collectors.toList());
69+
.toList();
7170
}
7271

7372
/**

fanout-fanin/src/main/java/com/iluwatar/fanout/fanin/App.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.util.Arrays;
2828
import java.util.List;
29-
import java.util.stream.Collectors;
3029

3130
import lombok.extern.slf4j.Slf4j;
3231

@@ -62,7 +61,7 @@ public static void main(String[] args) {
6261
LOGGER.info("Numbers to be squared and get sum --> {}", numbers);
6362

6463
final List<SquareNumberRequest> requests =
65-
numbers.stream().map(SquareNumberRequest::new).collect(Collectors.toList());
64+
numbers.stream().map(SquareNumberRequest::new).toList();
6665

6766
var consumer = new Consumer(0L);
6867

fanout-fanin/src/main/java/com/iluwatar/fanout/fanin/FanOutFanIn.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.concurrent.CompletableFuture;
2929
import java.util.concurrent.ExecutorService;
3030
import java.util.concurrent.Executors;
31-
import java.util.stream.Collectors;
3231

3332
/**
3433
* FanOutFanIn class processes long running requests, when any of the processes gets over, result is
@@ -54,7 +53,7 @@ public static Long fanOutFanIn(
5453
.map(
5554
request ->
5655
CompletableFuture.runAsync(() -> request.delayedSquaring(consumer), service))
57-
.collect(Collectors.toList());
56+
.toList();
5857

5958
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
6059

fanout-fanin/src/test/java/com/iluwatar/fanout/fanin/FanOutFanInTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import java.util.Arrays;
3131
import java.util.List;
32-
import java.util.stream.Collectors;
3332

3433
class FanOutFanInTest {
3534

@@ -38,7 +37,7 @@ void fanOutFanInTest() {
3837
final List<Long> numbers = Arrays.asList(1L, 3L, 4L, 7L, 8L);
3938

4039
final List<SquareNumberRequest> requests =
41-
numbers.stream().map(SquareNumberRequest::new).collect(Collectors.toList());
40+
numbers.stream().map(SquareNumberRequest::new).toList();
4241

4342
final Consumer consumer = new Consumer(0L);
4443

filterer/src/main/java/com/iluwatar/filterer/threat/SimpleProbabilisticThreatAwareSystem.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private List<ProbableThreat> filteredItems(
7676
final Predicate<? super ProbableThreat> predicate) {
7777
return this.threats.stream()
7878
.filter(predicate)
79-
.collect(Collectors.toUnmodifiableList());
79+
.toList();
8080
}
8181

8282
}

filterer/src/main/java/com/iluwatar/filterer/threat/SimpleThreatAwareSystem.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ private ThreatAwareSystem filteredGroup(Predicate<? super Threat> predicate) {
7474

7575
private List<Threat> filteredItems(Predicate<? super Threat> predicate) {
7676
return this.issues.stream()
77-
.filter(predicate)
78-
.collect(Collectors.toUnmodifiableList());
77+
.filter(predicate).toList();
7978
}
8079

8180
}

flux/src/test/java/com/iluwatar/flux/dispatcher/DispatcherTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import com.iluwatar.flux.action.MenuAction;
4040
import com.iluwatar.flux.action.MenuItem;
4141
import com.iluwatar.flux.store.Store;
42-
import java.util.stream.Collectors;
4342
import org.junit.jupiter.api.BeforeEach;
4443
import org.junit.jupiter.api.Test;
4544
import org.mockito.ArgumentCaptor;
@@ -90,12 +89,12 @@ void testMenuItemSelected() {
9089
final var menuActions = actions.stream()
9190
.filter(a -> a.getType().equals(ActionType.MENU_ITEM_SELECTED))
9291
.map(a -> (MenuAction) a)
93-
.collect(Collectors.toList());
92+
.toList();
9493

9594
final var contentActions = actions.stream()
9695
.filter(a -> a.getType().equals(ActionType.CONTENT_CHANGED))
9796
.map(a -> (ContentAction) a)
98-
.collect(Collectors.toList());
97+
.toList();
9998

10099
assertEquals(2, menuActions.size());
101100
assertEquals(1, menuActions.stream().map(MenuAction::getMenuItem).filter(MenuItem.HOME::equals)

layers/src/main/java/com/iluwatar/layers/service/CakeBakingServiceImpl.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import java.util.HashSet;
3939
import java.util.List;
4040
import java.util.Set;
41-
import java.util.stream.Collectors;
4241
import org.springframework.context.support.AbstractApplicationContext;
4342
import org.springframework.context.support.ClassPathXmlApplicationContext;
4443
import org.springframework.stereotype.Service;
@@ -62,7 +61,7 @@ public void bakeNewCake(CakeInfo cakeInfo) throws CakeBakingException {
6261
var allToppings = getAvailableToppingEntities();
6362
var matchingToppings =
6463
allToppings.stream().filter(t -> t.getName().equals(cakeInfo.cakeToppingInfo.name))
65-
.collect(Collectors.toList());
64+
.toList();
6665
if (matchingToppings.isEmpty()) {
6766
throw new CakeBakingException(String.format("Topping %s is not available",
6867
cakeInfo.cakeToppingInfo.name));

leader-election/src/main/java/com/iluwatar/leaderelection/AbstractMessageManager.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
*/
2525
package com.iluwatar.leaderelection;
2626

27-
import java.util.List;
2827
import java.util.Map;
29-
import java.util.stream.Collectors;
3028

3129
/**
3230
* Abstract class of all the message manager classes.
@@ -56,13 +54,13 @@ protected Instance findNextInstance(int currentId) {
5654
.stream()
5755
.filter((i) -> i > currentId && instanceMap.get(i).isAlive())
5856
.sorted()
59-
.collect(Collectors.toList());
57+
.toList();
6058
if (candidateList.isEmpty()) {
6159
var index = instanceMap.keySet()
6260
.stream()
6361
.filter((i) -> instanceMap.get(i).isAlive())
6462
.sorted()
65-
.collect(Collectors.toList())
63+
.toList()
6664
.get(0);
6765
result = instanceMap.get(index);
6866
} else {

leader-election/src/main/java/com/iluwatar/leaderelection/bully/BullyMessageManager.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.iluwatar.leaderelection.MessageType;
3131
import java.util.List;
3232
import java.util.Map;
33-
import java.util.stream.Collectors;
3433

3534
/**
3635
* Implementation of BullyMessageManager.
@@ -115,7 +114,7 @@ private List<Integer> findElectionCandidateInstanceList(int currentId) {
115114
return instanceMap.keySet()
116115
.stream()
117116
.filter((i) -> i < currentId && instanceMap.get(i).isAlive())
118-
.collect(Collectors.toList());
117+
.toList();
119118
}
120119

121120
}

leader-election/src/main/java/com/iluwatar/leaderelection/ring/RingInstance.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.iluwatar.leaderelection.Message;
2929
import com.iluwatar.leaderelection.MessageManager;
3030
import java.util.Arrays;
31-
import java.util.stream.Collectors;
3231
import lombok.extern.slf4j.Slf4j;
3332

3433
/**
@@ -88,7 +87,7 @@ protected void handleElectionMessage(Message message) {
8887
var candidateList = Arrays.stream(content.trim().split(","))
8988
.map(Integer::valueOf)
9089
.sorted()
91-
.collect(Collectors.toList());
90+
.toList();
9291
if (candidateList.contains(localId)) {
9392
var newLeaderId = candidateList.get(0);
9493
LOGGER.info(INSTANCE + localId + " - New leader should be " + newLeaderId + ".");

serialized-entity/pom.xml

-26
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!--
3-
4-
This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
5-
6-
The MIT License
7-
Copyright © 2014-2022 Ilkka Seppälä
8-
9-
Permission is hereby granted, free of charge, to any person obtaining a copy
10-
of this software and associated documentation files (the "Software"), to deal
11-
in the Software without restriction, including without limitation the rights
12-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13-
copies of the Software, and to permit persons to whom the Software is
14-
furnished to do so, subject to the following conditions:
15-
16-
The above copyright notice and this permission notice shall be included in
17-
all copies or substantial portions of the Software.
18-
19-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25-
THE SOFTWARE.
26-
27-
-->
282
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
293
<modelVersion>4.0.0</modelVersion>
304
<parent>

serialized-entity/src/main/java/com/iluwatar/serializedentity/App.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
3+
*
24
* The MIT License
35
* Copyright © 2014-2022 Ilkka Seppälä
46
*
@@ -125,4 +127,4 @@ private static DataSource createDataSource() {
125127
dataSource.setURL(DB_URL);
126128
return dataSource;
127129
}
128-
}
130+
}

serialized-entity/src/main/java/com/iluwatar/serializedentity/Country.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
3+
*
24
* The MIT License
35
* Copyright © 2014-2022 Ilkka Seppälä
46
*

0 commit comments

Comments
 (0)