BAEL-1466 Removed the Unnecessary code.

This commit is contained in:
Sandip Singh 2018-10-01 11:01:14 +05:30
parent d152facd1d
commit af526099b5
3 changed files with 2 additions and 94 deletions

View File

@ -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<Customer> {
public static final String ID = CustomerWithMaxAge.class.getSimpleName();
private static final long serialVersionUID = -6023734758827953742L;
@Override
public void execute(FunctionContext<Customer> context) {
RegionFunctionContext regionContext = (RegionFunctionContext) context;
Region<Integer, Customer> region = regionContext.getDataSet();
Comparator<Customer> ageComparator = Comparator.comparing(Customer::getAge);
Optional<Customer> customer = region.entrySet()
.stream()
.map(Map.Entry::getValue)
.max(ageComparator);
customer.ifPresent(c -> context.getResultSender()
.lastResult(c));
}
@Override
public String getId() {
return ID;
}
}

View File

@ -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<Integer, String> region = regionContext.getDataSet();
List<Integer> primes = new ArrayList<>();
Set<Integer> 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;
}
}

View File

@ -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 {