Skip to content

Instantly share code, notes, and snippets.

@Jayasagar
Created December 17, 2017 15:20
Show Gist options
  • Save Jayasagar/3f9e227addd888607a36808ad9db961a to your computer and use it in GitHub Desktop.
Save Jayasagar/3f9e227addd888607a36808ad9db961a to your computer and use it in GitHub Desktop.
Map<String, Map<Thing, Boolean>> consumerWithEachDeviceStatus = consumerList
.stream()
.flatMap(consumer -> consumer.getThings()
.stream()
.map(thing -> new AbstractMap.SimpleImmutableEntry<>(consumer.getName(), thing))
)
.collect(Collectors.groupingBy(entry -> entry.getKey(),
Collectors.toMap(AbstractMap.SimpleImmutableEntry::getValue, entry -> entry.getValue().isRunning())));
System.out.println(consumerWithEachDeviceStatus);
//Output: {Bob={Thing(name=AgriFieldSensor)=true, Thing(name=EyeVirusDetector)=true, Thing(name=Bulb)=true, Thing(name=MotionDetector)=true}, Satti={Thing(name=AgriFieldSensor)=true, Thing(name=MotionDetector)=true}, Sri={Thing(name=EyeVirusDetector)=true, Thing(name=Bulb)=true}, Malli={Thing(name=Bulb)=true, Thing(name=MotionDetector)=true}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment