/** * Convert the project result set to {@link SubscribingProjectVo} */ private Map<Integer, SubscribingProjectVo> toProjects(final List<Object[]> projects) { return projects.stream().map(rs -> { // Build the project final SubscribingProjectVo project = new SubscribingProjectVo(); project.setId((Integer) rs[0]); project.setName((String) rs[1]); project.setPkey((String) rs[2]); // Also save it for indexed search return project; }).collect(Collectors.toMap(SubscribingProjectVo::getId, Function.identity())); }
/** * Convert the subscriptions result set to {@link SubscriptionLightVo} */ private Collection<SubscriptionLightVo> toSubscriptions(final List<Object[]> subscriptions, final Map<Integer, SubscribingProjectVo> projects) { // Prepare the subscriptions container with project name ordering return subscriptions.stream().filter(rs -> projects.containsKey(rs[1])).map(rs -> { // Build the subscription data final SubscriptionLightVo vo = new SubscriptionLightVo(); vo.setId((Integer) rs[0]); vo.setProject((Integer) rs[1]); vo.setNode((String) rs[2]); return vo; }).collect( () -> new TreeSet<>((o1, o2) -> (projects.get(o1.getProject()).getName() + "," + o1.getId()) .compareToIgnoreCase(projects.get(o2.getProject()).getName() + "," + o2.getId())), TreeSet::add, TreeSet::addAll); }