mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-13 14:16:02 +00:00
feature: added code refactoring changes for 2378 (#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 <aparna@aparnas-MacBook-Air.local>
This commit is contained in:
1 parent
6693527485
commit
147e2e681a
32 files changed
+202
-134
No files matched your search
@@ -1,30 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
|
||||||
|
|
||||||
This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
|
||||||
|
|
||||||
The MIT License
|
|
||||||
Copyright © 2014-2022 Ilkka Seppälä
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
|
|
||||||
-->
|
|
||||||
<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">
|
<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">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
|
|||||||
@@ -1,27 +1,3 @@
|
|||||||
/*
|
|
||||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
|
||||||
*
|
|
||||||
* The MIT License
|
|
||||||
* Copyright © 2014-2022 Ilkka Seppälä
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.iluwatar.collectingparameter;
|
package com.iluwatar.collectingparameter;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|||||||
+1
-1
@@ -31,4 +31,4 @@ public class PrinterItem {
|
|||||||
this.isDoubleSided = isDoubleSided;
|
this.isDoubleSided = isDoubleSided;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,27 +1,3 @@
|
|||||||
/*
|
|
||||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
|
||||||
*
|
|
||||||
* The MIT License
|
|
||||||
* Copyright © 2014-2022 Ilkka Seppälä
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.iluwatar.collectingparameter;
|
package com.iluwatar.collectingparameter;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|||||||
+2
-2
@@ -56,7 +56,7 @@ public class FunctionalProgramming {
|
|||||||
public static List<String> getModelsAfter2000(List<Car> cars) {
|
public static List<String> getModelsAfter2000(List<Car> cars) {
|
||||||
return cars.stream().filter(car -> car.getYear() > 2000)
|
return cars.stream().filter(car -> car.getYear() > 2000)
|
||||||
.sorted(Comparator.comparing(Car::getYear))
|
.sorted(Comparator.comparing(Car::getYear))
|
||||||
.map(Car::getModel).collect(Collectors.toList());
|
.map(Car::getModel).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,6 +78,6 @@ public class FunctionalProgramming {
|
|||||||
public static List<Car> getSedanCarsOwnedSortedByDate(List<Person> persons) {
|
public static List<Car> getSedanCarsOwnedSortedByDate(List<Person> persons) {
|
||||||
return persons.stream().map(Person::getCars).flatMap(List::stream)
|
return persons.stream().map(Person::getCars).flatMap(List::stream)
|
||||||
.filter(car -> Category.SEDAN.equals(car.getCategory()))
|
.filter(car -> Category.SEDAN.equals(car.getCategory()))
|
||||||
.sorted(Comparator.comparing(Car::getYear)).collect(Collectors.toList());
|
.sorted(Comparator.comparing(Car::getYear)).toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -27,7 +27,7 @@
|
|||||||
-->
|
-->
|
||||||
<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">
|
<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">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.26.0-SNAPSHOT</version>
|
<version>1.26.0-SNAPSHOT</version>
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ package com.iluwatar.converter;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,7 +73,7 @@ public class Converter<T, U> {
|
|||||||
* with the conversion function
|
* with the conversion function
|
||||||
*/
|
*/
|
||||||
public final List<U> createFromDtos(final Collection<T> dtos) {
|
public final List<U> createFromDtos(final Collection<T> dtos) {
|
||||||
return dtos.stream().map(this::convertFromDto).collect(Collectors.toList());
|
return dtos.stream().map(this::convertFromDto).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,7 +84,7 @@ public class Converter<T, U> {
|
|||||||
* with the conversion function
|
* with the conversion function
|
||||||
*/
|
*/
|
||||||
public final List<T> createFromEntities(final Collection<U> entities) {
|
public final List<T> createFromEntities(final Collection<U> entities) {
|
||||||
return entities.stream().map(this::convertFromEntity).collect(Collectors.toList());
|
return entities.stream().map(this::convertFromEntity).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-3
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.datatransfer.product;
|
package com.iluwatar.datatransfer.product;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The resource class which serves product information. This class act as server in the demo. Which
|
* The resource class which serves product information. This class act as server in the demo. Which
|
||||||
@@ -54,7 +53,7 @@ public class ProductResource {
|
|||||||
.map(p -> new ProductDto.Response.Private().setId(p.getId()).setName(p.getName())
|
.map(p -> new ProductDto.Response.Private().setId(p.getId()).setName(p.getName())
|
||||||
.setCost(p.getCost())
|
.setCost(p.getCost())
|
||||||
.setPrice(p.getPrice()))
|
.setPrice(p.getPrice()))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +66,7 @@ public class ProductResource {
|
|||||||
.stream()
|
.stream()
|
||||||
.map(p -> new ProductDto.Response.Public().setId(p.getId()).setName(p.getName())
|
.map(p -> new ProductDto.Response.Public().setId(p.getId()).setName(p.getName())
|
||||||
.setPrice(p.getPrice()))
|
.setPrice(p.getPrice()))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ package com.iluwatar.fanout.fanin;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ public class App {
|
|||||||
LOGGER.info("Numbers to be squared and get sum --> {}", numbers);
|
LOGGER.info("Numbers to be squared and get sum --> {}", numbers);
|
||||||
|
|
||||||
final List<SquareNumberRequest> requests =
|
final List<SquareNumberRequest> requests =
|
||||||
numbers.stream().map(SquareNumberRequest::new).collect(Collectors.toList());
|
numbers.stream().map(SquareNumberRequest::new).toList();
|
||||||
|
|
||||||
var consumer = new Consumer(0L);
|
var consumer = new Consumer(0L);
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import java.util.List;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FanOutFanIn class processes long running requests, when any of the processes gets over, result is
|
* FanOutFanIn class processes long running requests, when any of the processes gets over, result is
|
||||||
@@ -54,7 +53,7 @@ public class FanOutFanIn {
|
|||||||
.map(
|
.map(
|
||||||
request ->
|
request ->
|
||||||
CompletableFuture.runAsync(() -> request.delayedSquaring(consumer), service))
|
CompletableFuture.runAsync(() -> request.delayedSquaring(consumer), service))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
|
|
||||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
class FanOutFanInTest {
|
class FanOutFanInTest {
|
||||||
|
|
||||||
@@ -38,7 +37,7 @@ class FanOutFanInTest {
|
|||||||
final List<Long> numbers = Arrays.asList(1L, 3L, 4L, 7L, 8L);
|
final List<Long> numbers = Arrays.asList(1L, 3L, 4L, 7L, 8L);
|
||||||
|
|
||||||
final List<SquareNumberRequest> requests =
|
final List<SquareNumberRequest> requests =
|
||||||
numbers.stream().map(SquareNumberRequest::new).collect(Collectors.toList());
|
numbers.stream().map(SquareNumberRequest::new).toList();
|
||||||
|
|
||||||
final Consumer consumer = new Consumer(0L);
|
final Consumer consumer = new Consumer(0L);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -76,7 +76,7 @@ public class SimpleProbabilisticThreatAwareSystem implements ProbabilisticThreat
|
|||||||
final Predicate<? super ProbableThreat> predicate) {
|
final Predicate<? super ProbableThreat> predicate) {
|
||||||
return this.threats.stream()
|
return this.threats.stream()
|
||||||
.filter(predicate)
|
.filter(predicate)
|
||||||
.collect(Collectors.toUnmodifiableList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -74,8 +74,7 @@ public class SimpleThreatAwareSystem implements ThreatAwareSystem {
|
|||||||
|
|
||||||
private List<Threat> filteredItems(Predicate<? super Threat> predicate) {
|
private List<Threat> filteredItems(Predicate<? super Threat> predicate) {
|
||||||
return this.issues.stream()
|
return this.issues.stream()
|
||||||
.filter(predicate)
|
.filter(predicate).toList();
|
||||||
.collect(Collectors.toUnmodifiableList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,6 @@ import com.iluwatar.flux.action.ContentAction;
|
|||||||
import com.iluwatar.flux.action.MenuAction;
|
import com.iluwatar.flux.action.MenuAction;
|
||||||
import com.iluwatar.flux.action.MenuItem;
|
import com.iluwatar.flux.action.MenuItem;
|
||||||
import com.iluwatar.flux.store.Store;
|
import com.iluwatar.flux.store.Store;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
@@ -90,12 +89,12 @@ class DispatcherTest {
|
|||||||
final var menuActions = actions.stream()
|
final var menuActions = actions.stream()
|
||||||
.filter(a -> a.getType().equals(ActionType.MENU_ITEM_SELECTED))
|
.filter(a -> a.getType().equals(ActionType.MENU_ITEM_SELECTED))
|
||||||
.map(a -> (MenuAction) a)
|
.map(a -> (MenuAction) a)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
|
|
||||||
final var contentActions = actions.stream()
|
final var contentActions = actions.stream()
|
||||||
.filter(a -> a.getType().equals(ActionType.CONTENT_CHANGED))
|
.filter(a -> a.getType().equals(ActionType.CONTENT_CHANGED))
|
||||||
.map(a -> (ContentAction) a)
|
.map(a -> (ContentAction) a)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
|
|
||||||
assertEquals(2, menuActions.size());
|
assertEquals(2, menuActions.size());
|
||||||
assertEquals(1, menuActions.stream().map(MenuAction::getMenuItem).filter(MenuItem.HOME::equals)
|
assertEquals(1, menuActions.stream().map(MenuAction::getMenuItem).filter(MenuItem.HOME::equals)
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import org.springframework.context.support.AbstractApplicationContext;
|
import org.springframework.context.support.AbstractApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -62,7 +61,7 @@ public class CakeBakingServiceImpl implements CakeBakingService {
|
|||||||
var allToppings = getAvailableToppingEntities();
|
var allToppings = getAvailableToppingEntities();
|
||||||
var matchingToppings =
|
var matchingToppings =
|
||||||
allToppings.stream().filter(t -> t.getName().equals(cakeInfo.cakeToppingInfo.name))
|
allToppings.stream().filter(t -> t.getName().equals(cakeInfo.cakeToppingInfo.name))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
if (matchingToppings.isEmpty()) {
|
if (matchingToppings.isEmpty()) {
|
||||||
throw new CakeBakingException(String.format("Topping %s is not available",
|
throw new CakeBakingException(String.format("Topping %s is not available",
|
||||||
cakeInfo.cakeToppingInfo.name));
|
cakeInfo.cakeToppingInfo.name));
|
||||||
|
|||||||
+2
-4
@@ -24,9 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.leaderelection;
|
package com.iluwatar.leaderelection;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class of all the message manager classes.
|
* Abstract class of all the message manager classes.
|
||||||
@@ -56,13 +54,13 @@ public abstract class AbstractMessageManager implements MessageManager {
|
|||||||
.stream()
|
.stream()
|
||||||
.filter((i) -> i > currentId && instanceMap.get(i).isAlive())
|
.filter((i) -> i > currentId && instanceMap.get(i).isAlive())
|
||||||
.sorted()
|
.sorted()
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
if (candidateList.isEmpty()) {
|
if (candidateList.isEmpty()) {
|
||||||
var index = instanceMap.keySet()
|
var index = instanceMap.keySet()
|
||||||
.stream()
|
.stream()
|
||||||
.filter((i) -> instanceMap.get(i).isAlive())
|
.filter((i) -> instanceMap.get(i).isAlive())
|
||||||
.sorted()
|
.sorted()
|
||||||
.collect(Collectors.toList())
|
.toList()
|
||||||
.get(0);
|
.get(0);
|
||||||
result = instanceMap.get(index);
|
result = instanceMap.get(index);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-2
@@ -30,7 +30,6 @@ import com.iluwatar.leaderelection.Message;
|
|||||||
import com.iluwatar.leaderelection.MessageType;
|
import com.iluwatar.leaderelection.MessageType;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of BullyMessageManager.
|
* Implementation of BullyMessageManager.
|
||||||
@@ -115,7 +114,7 @@ public class BullyMessageManager extends AbstractMessageManager {
|
|||||||
return instanceMap.keySet()
|
return instanceMap.keySet()
|
||||||
.stream()
|
.stream()
|
||||||
.filter((i) -> i < currentId && instanceMap.get(i).isAlive())
|
.filter((i) -> i < currentId && instanceMap.get(i).isAlive())
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,6 @@ import com.iluwatar.leaderelection.AbstractInstance;
|
|||||||
import com.iluwatar.leaderelection.Message;
|
import com.iluwatar.leaderelection.Message;
|
||||||
import com.iluwatar.leaderelection.MessageManager;
|
import com.iluwatar.leaderelection.MessageManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,7 +87,7 @@ public class RingInstance extends AbstractInstance {
|
|||||||
var candidateList = Arrays.stream(content.trim().split(","))
|
var candidateList = Arrays.stream(content.trim().split(","))
|
||||||
.map(Integer::valueOf)
|
.map(Integer::valueOf)
|
||||||
.sorted()
|
.sorted()
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
if (candidateList.contains(localId)) {
|
if (candidateList.contains(localId)) {
|
||||||
var newLeaderId = candidateList.get(0);
|
var newLeaderId = candidateList.get(0);
|
||||||
LOGGER.info(INSTANCE + localId + " - New leader should be " + newLeaderId + ".");
|
LOGGER.info(INSTANCE + localId + " - New leader should be " + newLeaderId + ".");
|
||||||
|
|||||||
@@ -1,30 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
|
||||||
|
|
||||||
This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
|
||||||
|
|
||||||
The MIT License
|
|
||||||
Copyright © 2014-2022 Ilkka Seppälä
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
|
|
||||||
-->
|
|
||||||
<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">
|
<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">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright © 2014-2022 Ilkka Seppälä
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
@@ -125,4 +127,4 @@ public class App {
|
|||||||
dataSource.setURL(DB_URL);
|
dataSource.setURL(DB_URL);
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright © 2014-2022 Ilkka Seppälä
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright © 2014-2022 Ilkka Seppälä
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright © 2014-2022 Ilkka Seppälä
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright © 2014-2022 Ilkka Seppälä
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
|
||||||
|
The MIT License
|
||||||
|
Copyright © 2014-2022 Ilkka Seppälä
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
-->
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|||||||
@@ -1,3 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
package com.iluwatar.servicetoworker;
|
package com.iluwatar.servicetoworker;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|||||||
@@ -1,3 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
package com.iluwatar.servicetoworker;
|
package com.iluwatar.servicetoworker;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|||||||
@@ -1,3 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
package com.iluwatar.servicetoworker;
|
package com.iluwatar.servicetoworker;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|||||||
@@ -1,3 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
package com.iluwatar.servicetoworker;
|
package com.iluwatar.servicetoworker;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|||||||
@@ -1,3 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
package com.iluwatar.servicetoworker;
|
package com.iluwatar.servicetoworker;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|||||||
@@ -1,3 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
package com.iluwatar.servicetoworker;
|
package com.iluwatar.servicetoworker;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public abstract class TaskTest<T extends Task> {
|
|||||||
.stream()
|
.stream()
|
||||||
.map(TaskTest::get)
|
.map(TaskTest::get)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
|
|
||||||
service.shutdownNow();
|
service.shutdownNow();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user