match - Comparing consecutive elements in a queue -


i have queue of elements, sorted date. need extract first n elements, have same date , add them temporary arraylist, choose 1 of them , scrap others. after need continue doing same thing next n elements of queue same date (extract them temp list , on) until have no more items in queue.

        // notes understand code         priorityqueue<results> r, size(4), elementsequalbytime(1=2,3=4);          list<comments> c, size(2);         arraylist temp;          if (c.size() != r.size() && resultiter.hasnext()) {         //first iteration compare element 0 -> 100% true            resultobject r2 = resultiter.next();            resultobject r1 = r2;          while (resultiter.hasnext() && r1.gettime().equals(r2.gettime())) {             temp.add(r1);             //we add matching elements before continue             r1 = r2;             temp.add(r1);               if (resultiter.hasnext()) {             //after add 2 matching elements continue                    r2 = resultiter.next();                 }             }             //use items in temp                    temp.clear();         }  

right works 1st set of elements, on 2nd iteration adds no elements temp arraylist. i'd appreciate solution, open different suggestions.

 boolean check (list<element> elements,element element)     {         for(element element1:elements)             if(element1.equals(element))                 return true;         return false;     }      void stuff() {      // notes understand code     priorityqueue<element> r = new priorityqueue<element>();     list<element> c;     list<element> temp = new arraylist<element>();      for(element element:r)     {             if(!check(temp, element))             {                 // stuff temp                 temp = new arraylist<element>();              }             temp.add(element);         }  } 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -