diff --git a/apache-geode/src/main/java/com/baeldung/geode/functions/CustomerWithMaxAge.java b/apache-geode/src/main/java/com/baeldung/geode/functions/CustomerWithMaxAge.java deleted file mode 100644 index ef729a1ac2..0000000000 --- a/apache-geode/src/main/java/com/baeldung/geode/functions/CustomerWithMaxAge.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.geode.functions; - -import com.baeldung.geode.Customer; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.execute.Function; -import org.apache.geode.cache.execute.FunctionContext; -import org.apache.geode.cache.execute.RegionFunctionContext; - -import java.util.Comparator; -import java.util.Map; -import java.util.Optional; - -public class CustomerWithMaxAge implements Function { - - public static final String ID = CustomerWithMaxAge.class.getSimpleName(); - - private static final long serialVersionUID = -6023734758827953742L; - - @Override - public void execute(FunctionContext context) { - RegionFunctionContext regionContext = (RegionFunctionContext) context; - Region region = regionContext.getDataSet(); - - Comparator ageComparator = Comparator.comparing(Customer::getAge); - - Optional customer = region.entrySet() - .stream() - .map(Map.Entry::getValue) - .max(ageComparator); - - customer.ifPresent(c -> context.getResultSender() - .lastResult(c)); - } - - @Override - public String getId() { - return ID; - } -} diff --git a/apache-geode/src/main/java/com/baeldung/geode/functions/PrimeNumber.java b/apache-geode/src/main/java/com/baeldung/geode/functions/PrimeNumber.java deleted file mode 100644 index 411816348a..0000000000 --- a/apache-geode/src/main/java/com/baeldung/geode/functions/PrimeNumber.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.geode.functions; - -import org.apache.geode.cache.Region; -import org.apache.geode.cache.execute.Function; -import org.apache.geode.cache.execute.FunctionContext; -import org.apache.geode.cache.execute.RegionFunctionContext; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -public class PrimeNumber implements Function { - - public static final String ID = PrimeNumber.class.getSimpleName(); - - @Override - public void execute(FunctionContext context) { - RegionFunctionContext regionContext = (RegionFunctionContext) context; - Region region = regionContext.getDataSet(); - - List primes = new ArrayList<>(); - Set keys = region.keySet(); - for (Integer key : keys) { - if (isPrime(key)) { - primes.add(key); - } - } - Collections.sort(primes); - - context.getResultSender() - .lastResult(primes); - } - - @Override - public String getId() { - return ID; - } - - private boolean isPrime(int number) { - int limit = (int) Math.floor(Math.sqrt(number)); - for (int divisor = 2; divisor <= limit; ++divisor) { - if (number % divisor == 0) { - return false; - } - } - return true; - } -} diff --git a/apache-geode/src/test/java/com/baeldung/geode/GeodeSamplesIntegrationTest.java b/apache-geode/src/test/java/com/baeldung/geode/GeodeSamplesIntegrationTest.java index eb9affde8e..b96d2c9b6a 100644 --- a/apache-geode/src/test/java/com/baeldung/geode/GeodeSamplesIntegrationTest.java +++ b/apache-geode/src/test/java/com/baeldung/geode/GeodeSamplesIntegrationTest.java @@ -1,7 +1,5 @@ package com.baeldung.geode; -import com.baeldung.geode.functions.CustomerWithMaxAge; -import com.baeldung.geode.functions.PrimeNumber; import com.baeldung.geode.functions.UpperCaseNames; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.ClientCache; @@ -9,21 +7,19 @@ import org.apache.geode.cache.client.ClientCacheFactory; import org.apache.geode.cache.client.ClientRegionShortcut; import org.apache.geode.cache.execute.Execution; import org.apache.geode.cache.execute.FunctionService; -import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.cache.query.*; import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.util.*; +import java.util.HashMap; +import java.util.Map; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; -import java.util.stream.IntStream; import java.util.stream.Stream; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; public class GeodeSamplesIntegrationTest {