public static String findNodeWithNextLowestSN ( List < String > children , String node ) { List < String > sortedChildren = children . stream ( ) . sorted ( ( String o1 , String o2 ) -> Long . compare ( getSequenceNumber ( o1 ) , getSequenceNumber ( o2 ) ) ) . collect ( Collectors . toList ( ) ) ; int index = sortedChildren . indexOf ( node ) ; if ( index > 0 ) { return sortedChildren . get ( index - 1 ) ; } else if ( index == 0 ) { return node ; } else { return null ; } }
Finds node with next lowest sequence number than the given node within the given list of nodes .