protected PredicateLevelProposal proposeForGroupingMap ( ImmutableMultimap < ImmutableList < VariableOrGroundTerm > , ExtensionalDataNode > groupingMap ) throws AtomUnificationException { ImmutableCollection < Collection < ExtensionalDataNode >> dataNodeGroups = groupingMap . asMap ( ) . values ( ) ; try { /* * Collection of unifying substitutions */ ImmutableSet < ImmutableSubstitution < VariableOrGroundTerm >> unifyingSubstitutions = dataNodeGroups . stream ( ) . filter ( g -> g . size ( ) > 1 ) . map ( redundantNodes -> { try { return unifyRedundantNodes ( redundantNodes ) ; } catch ( AtomUnificationException e ) { throw new AtomUnificationRuntimeException ( e ) ; } } ) . filter ( s -> ! s . isEmpty ( ) ) . collect ( ImmutableCollectors . toSet ( ) ) ; /* * All the nodes that have been at least once dominated (--> could thus be removed). * * Not parallellizable */ ImmutableSet < ExtensionalDataNode > removableNodes = ImmutableSet . copyOf ( dataNodeGroups . stream ( ) . filter ( sameRowDataNodes -> sameRowDataNodes . size ( ) > 1 ) . reduce ( new Dominance ( ) , Dominance :: update , ( dom1 , dom2 ) -> { throw new IllegalStateException ( "Cannot be run in parallel" ) ; } ) . getRemovalNodes ( ) ) ; return new PredicateLevelProposal ( unifyingSubstitutions , removableNodes ) ; /* * Trick: rethrow the exception */ } catch ( AtomUnificationRuntimeException e ) { throw e . checkedException ; } }
groupingMap groups data nodes that are being joined on the unique constraints