protected static Map < String , List < Statement > > addStatementToGroups ( Statement statement , Map < String , List < Statement > > claims ) { Map < String , List < Statement > > newGroups = new HashMap <> ( claims ) ; String pid = statement . getMainSnak ( ) . getPropertyId ( ) . getId ( ) ; if ( newGroups . containsKey ( pid ) ) { List < Statement > newGroup = new ArrayList <> ( newGroups . get ( pid ) . size ( ) ) ; boolean statementReplaced = false ; for ( Statement existingStatement : newGroups . get ( pid ) ) { if ( existingStatement . getStatementId ( ) . equals ( statement . getStatementId ( ) ) && ! existingStatement . getStatementId ( ) . isEmpty ( ) ) { statementReplaced = true ; newGroup . add ( statement ) ; } else { newGroup . add ( existingStatement ) ; } } if ( ! statementReplaced ) { newGroup . add ( statement ) ; } newGroups . put ( pid , newGroup ) ; } else { newGroups . put ( pid , Collections . singletonList ( statement ) ) ; } return newGroups ; }
Adds a Statement to a given collection of statement groups . If the statement id is not null and matches that of an existing statement this statement will be replaced .