Java Strem.map 使用实例
从对象中获取属性(并去重)
public List<Integer> checkRoomIds(Integer[] roomIds) {
if (null == roomIds || 0 == roomIds.length) {
return null;
}
EntityWrapper<DeviceInfo> entityWrapper = new EntityWrapper<>();
// 查找房间列表中 是否有正在使用的设备
entityWrapper.in("room_id", roomIds);
List<DeviceInfo> deviceInfoList = deviceInfoMapper.selectList(entityWrapper);
if (null == deviceInfoList || 0 == deviceInfoList.size()) {
return null;
}
// 返回存在设备使用的房间号 并去重
return deviceInfoList.stream().map(DeviceInfo::getRoomId).distinct().collect(Collectors.toList());
}