Sho SHIMIZU
Committed by Gerrit Code Review

More idiomatic code in Stream API

Change-Id: Ifa5a311cfc1ce43f5eab80be9ddce5fa36e47d92
...@@ -40,6 +40,7 @@ import java.util.List; ...@@ -40,6 +40,7 @@ import java.util.List;
40 import java.util.Map; 40 import java.util.Map;
41 import java.util.Optional; 41 import java.util.Optional;
42 import java.util.Set; 42 import java.util.Set;
43 +import java.util.function.Function;
43 import java.util.stream.Collectors; 44 import java.util.stream.Collectors;
44 45
45 class MockResourceService implements ResourceService { 46 class MockResourceService implements ResourceService {
...@@ -49,7 +50,7 @@ class MockResourceService implements ResourceService { ...@@ -49,7 +50,7 @@ class MockResourceService implements ResourceService {
49 @Override 50 @Override
50 public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<Resource> resources) { 51 public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<Resource> resources) {
51 assignment.putAll( 52 assignment.putAll(
52 - resources.stream().collect(Collectors.toMap(x -> x, x -> consumer)) 53 + resources.stream().collect(Collectors.toMap(Function.identity(), x -> consumer))
53 ); 54 );
54 55
55 return resources.stream() 56 return resources.stream()
......
...@@ -50,6 +50,7 @@ import org.slf4j.Logger; ...@@ -50,6 +50,7 @@ import org.slf4j.Logger;
50 50
51 import java.util.Collection; 51 import java.util.Collection;
52 import java.util.Map; 52 import java.util.Map;
53 +import java.util.function.Function;
53 import java.util.stream.Collectors; 54 import java.util.stream.Collectors;
54 55
55 import static org.slf4j.LoggerFactory.getLogger; 56 import static org.slf4j.LoggerFactory.getLogger;
...@@ -209,7 +210,7 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M ...@@ -209,7 +210,7 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M
209 //FIXME: FOLLOWING CODE CANNOT BE TESTED UNTIL SOMETHING THAT 210 //FIXME: FOLLOWING CODE CANNOT BE TESTED UNTIL SOMETHING THAT
210 //FIXME: IMPLEMENTS METERS EXISTS 211 //FIXME: IMPLEMENTS METERS EXISTS
211 Map<Pair<DeviceId, MeterId>, Meter> storedMeterMap = store.getAllMeters().stream() 212 Map<Pair<DeviceId, MeterId>, Meter> storedMeterMap = store.getAllMeters().stream()
212 - .collect(Collectors.toMap(m -> Pair.of(m.deviceId(), m.id()), m -> m)); 213 + .collect(Collectors.toMap(m -> Pair.of(m.deviceId(), m.id()), Function.identity()));
213 214
214 meterEntries.stream() 215 meterEntries.stream()
215 .filter(m -> storedMeterMap.remove(Pair.of(m.deviceId(), m.id())) != null) 216 .filter(m -> storedMeterMap.remove(Pair.of(m.deviceId(), m.id())) != null)
......