public CharTrie reduceSimple ( CharTrie z , BiFunction < Long , Long , Long > fn ) { return reduce ( z , ( left , right ) -> { TreeMap < Character , ? extends TrieNode > leftChildren = null == left ? new TreeMap <> ( ) : left . getChildrenMap ( ) ; TreeMap < Character , ? extends TrieNode > rightChildren = null == right ? new TreeMap <> ( ) : right . getChildrenMap ( ) ; Map < Character , Long > map = Stream . of ( rightChildren . keySet ( ) , leftChildren . keySet ( ) ) . flatMap ( x -> x . stream ( ) ) . distinct ( ) . collect ( Collectors . toMap ( c -> c , ( Character c ) -> { assert ( null != leftChildren ) ; assert ( null != rightChildren ) ; assert ( null != c ) ; TrieNode leftChild = leftChildren . get ( c ) ; Long l = null == leftChild ? null : leftChild . getCursorCount ( ) ; TrieNode rightChild = rightChildren . get ( c ) ; Long r = null == rightChild ? null : rightChild . getCursorCount ( ) ; return fn . apply ( l , r ) ; } ) ) ; return new TreeMap <> ( map ) ; } ) ; }
Reduce simple char trie .