/** * Creates event handlers from a collection of {@link ChannelConnection}s and returns a Map sorted by connection sequence value. * * @param connections the connections * @return the sorted Map */ public static NavigableMap<Integer, List<EventHandler<RingBufferEvent>>> createAndSort(Collection<ChannelConnection> connections) { NavigableMap<Integer, List<EventHandler<RingBufferEvent>>> sorted = new TreeMap<>(); for (ChannelConnection connection : connections) { Integer sequence = connection.getSequence(); List<EventHandler<RingBufferEvent>> handlers = sorted.get(sequence); if (handlers == null) { handlers = new ArrayList<>(); sorted.put(sequence, handlers); } boolean channelEvent = isChannelEvent(connection); handlers.add(new ChannelEventHandler(connection, channelEvent)); } return sorted; }