java - The algorithm compares two lists, synchronization tables -
the algorithm compares 2 lists list, synchronization tables
i need synchronize local table table loaded server. decided compare 2 stages list (local list , server). initially, list sorted. remains landmark in comparing of id.
if id on local list is, , server not present, removal of entries local database (delete). if id equal local server , update (update). if id server there, , there no local, add (select). problem have in phase comparison, somewhere wrong, not foreseen.
i throw off comparison algorithm, began write, not finish image , example. please modify it. image example: http://c2n.me/3mmgizg
list<integer> server = new arraylist<>(); list<integer> local = new arraylist<>(); databasehandler db = new databasehandler(context); iterator<integer> seriter = server.iterator(); iterator<integer> lociter = local.iterator(); int item1 = seriter.next(); int item2 = lociter.next(); while(seriter.hasnext()) { if (item1 <item2) { db.addcourse(item1); item1 = seriter.next(); } else { if (lociter.hasnext()) { while (item2 < item1) { db.deletecourse(item2); item2 = lociter.next(); } if (item1 == item2) { db.updatecourse(item1); item2 = lociter.next(); item1 = seriter.next(); } } else { while(item1<item2) { db.addcourse(item1); item1 = seriter.next(); } if (item1 == item2) { db.updatecourse(item1); item1 = seriter.next(); } else { db.deletecourse(item2 ); continue other; } } } other: while(item1>item2) { db.addcourse(item1); item1 = seriter.next(); } }
i'm not sure understand you're saying. if want make local list = server list, follows:
for(int = 0; < server.size(); i++) { local.set(i, server.get(i)); }
this iterate through items in server arraylist , change them value in local arraylist
Comments
Post a Comment