i having 1 list of custom objects (around 20,000 or 30,000 records), -> need compare records subsequent records based on 3 parameters(type, name , country )and -> if records find equal, have check date these 2 records -> , have keep record recent date validated status , marking other record old status.
note- max 1 record can equal 1 record / @ time not 3 or more records can equal
right now, using arraylist , implemented equals method in domain class based on 3 parameter. checking each record other records , if found equal -> doing date check , marking status accordingly , breaking , continuing other records -> @ end removing d records status 'old'
can achieve in java 8 or other apis apache commons, in effective way?
code snippet-
`public class domain implements comparable<domain> { private string type; private string name; private string country; private date vailddate; private string staus; getter setter equals method based on type, name , country public int compareto(domain domain) { return (this.vailddate).compareto(domain.getvailddate()); } } in spring service class public void savevalidatedrecords() throws ioexception { list<domain> validatedrecordsinfile = processexternalftpfile(); list<domain> dbrecords = dao.findrec(integer id); //i have compare db rec , file records , process according question , merging both list , processing list<domain> listtobesaved = new arraylist<domain>(dbrecords.size()+validatedrecordsinfile.size()); listtobesaved.addall(validatedrecordsinfile); listtobesaved.addall(dbrecords); (int i= 0; i< listtobesaved.size(); i++) { (int j= i+1;j< listtobesaved.size() ;j++) { if (listtobesaved.get(i).equals(listtobesaved.get(j)) ) { if(listtobesaved.get(i).getvaliddate().after(listtobesaved.get(j).getvaliddate()) { listtobesaved.get(i).getstatus("valid"); listtobesaved.get(j).getstatus("old"); break; //since 1 record equal , control goes outer } } } }`
i can use 2 list here, no need merge.
thanks
Comments
Post a Comment