@ Override public List < ProposalPersonContract > getNKeyPersons ( List < ? extends ProposalPersonContract > proposalPersons , int n ) { ProposalPersonContract proposalPerson , previousProposalPerson ; int size = proposalPersons . size ( ) ; for ( int i = size - 1 ; i > 0 ; i -- ) { proposalPerson = proposalPersons . get ( i ) ; previousProposalPerson = proposalPersons . get ( i - 1 ) ; if ( proposalPerson . getPersonId ( ) != null && previousProposalPerson . getPersonId ( ) != null && proposalPerson . getPersonId ( ) . equals ( previousProposalPerson . getPersonId ( ) ) ) { proposalPersons . remove ( i ) ; } else if ( proposalPerson . getRolodexId ( ) != null && previousProposalPerson . getRolodexId ( ) != null && proposalPerson . getRolodexId ( ) . equals ( previousProposalPerson . getRolodexId ( ) ) ) { proposalPersons . remove ( i ) ; } } size = proposalPersons . size ( ) ; List < ProposalPersonContract > firstNPersons = new ArrayList <> ( ) ; // Make sure we don't exceed the size of the list. if ( size > n ) { size = n ; } // remove extras for ( int i = 0 ; i < size ; i ++ ) { firstNPersons . add ( proposalPersons . get ( i ) ) ; } return firstNPersons ; }
This method limits the number of key persons to n returns list of key persons .