use of org.onosproject.net.group.Group.GroupState in project onos by opennetworkinglab.
the class GroupsListCommand method getSortedGroups.
/**
* Returns the list of devices sorted using the device ID URIs.
*
* @param deviceService device service
* @param groupService group service
* @return sorted device list
*/
protected SortedMap<Device, List<Group>> getSortedGroups(DeviceService deviceService, GroupService groupService) {
final GroupState groupsState = (this.state != null && !"any".equals(this.state)) ? GroupState.valueOf(this.state.toUpperCase()) : null;
final Iterable<Device> devices = Optional.ofNullable(uri).map(DeviceId::deviceId).map(deviceService::getDevice).map(dev -> (Iterable<Device>) Collections.singletonList(dev)).orElse(deviceService.getDevices());
SortedMap<Device, List<Group>> sortedGroups = new TreeMap<>(Comparators.ELEMENT_COMPARATOR);
for (Device d : devices) {
Stream<Group> groupStream = Lists.newArrayList(groupService.getGroups(d.id())).stream();
if (groupsState != null) {
groupStream = groupStream.filter(g -> g.state().equals(groupsState));
}
if (referencedOnly) {
groupStream = groupStream.filter(g -> g.referenceCount() != 0);
}
if (type != null && !"any".equals(type)) {
groupStream = groupStream.filter(g -> g.type().equals(GroupDescription.Type.valueOf(type.toUpperCase())));
}
if (unreferencedOnly) {
groupStream = groupStream.filter(g -> g.referenceCount() == 0);
}
sortedGroups.put(d, groupStream.sorted(Comparators.GROUP_COMPARATOR).collect(Collectors.toList()));
}
return sortedGroups;
}
Aggregations