[ create a new paste ] login | about

Link: http://codepad.org/gr5B8OJ3    [ raw code | fork ]

C++, pasted on Jul 15:
public class pagicon
{
   private integer counter=0;  //keeps track of the offset
   private integer list_size=10; //sets the page size or number of rows
   public integer total_size; //used to show user the total size of the list
   public list<integercounter> lsti = new list<integercounter>();  //wrapper list for holding integers + counter when the integer is added to list

   public pagicon() // constructor, makes a master list of int + counter (counters are modified later in getNumbers()
   {
       integer i;
       for(i=1;i<41;i++) // 1-40. code works PERFECTLY for non-10 multiples eg 11, 25, 99 etc, but fails on 10 multiples eg 10, 30, 40, 100, etc
       {
           lsti.add(new integercounter(i,counter));
       }
       total_size=lsti.size();
   }
   
    public list<integercounter> getNumbers() 
    {
      list<integercounter> lstin = new list<integercounter>();
      integercounter lstiw2= new integercounter(); //temp storage for manipulating counter var
      integer a,b;
      b=counter+list_size;
      
      if(counter > total_size)
      {}
      else
      {
      for(a=counter;a<b;a++)
      {
          if(a==(total_size))
              break;
          else if(a<(total_size))
          {
            lstiw2=lsti.get(a);             //temp storage for manipulating counter var
            integercounter lstiw = new integercounter(lstiw2.inn, counter);
          
            lstin.add(lstiw);
          }
      }
      }    
      return lstin;
   }

    public class integercounter  //wrapper for holding ints and counteers
    {
        public integer inn {get;set;}       // holds ints
        public integer co {get;set;}        // holds counter
        
        public integercounter(integer a, integer b)
        {
            inn = a;
            co = b;
        }
        public integercounter()
        {
            inn = 0;
            co = 0;
        }
    }

   public PageReference Beginning() { //user clicked beginning
      counter = 0;
      return null;
   }

   public PageReference Previous() { //user clicked previous button
      counter -= list_size;
      return null;
   }

   public PageReference Next() { //user clicked next button
      counter += list_size;
      //30+10 = 40
      return null;
   }

   public PageReference End() { //user clicked end
   
      counter = total_size - math.mod(total_size, list_size);
    //40-mod(40,10) = 40-0 = 40
      return null;
   }

   public Boolean getDisablePrevious() { 
      //this will disable the previous and beginning buttons
      if (counter>0) return false; else return true;
   }

   public Boolean getDisableNext() { //this will disable the next and end buttons
      if ((counter + list_size) < total_size) 
          return false; 
      else 
          return true;
   }

   public Integer getTotal_size() {
      return total_size;
   }

   public Integer getPageNumber(){ //wacky code. i have a headache trying to explain it.
                                   // i wrote/kludged it to only show eg "page 4/4" not "page 5/4".
                                   // it'd show "5/4" if i removed if/else and just returned "return counter/list_size + 1;"
   
       if ((counter/list_size) == 0)        
         return counter/list_size + 1;
        else if((counter+list_size)>total_size)
         return (counter/list_size);
        else
         return counter/list_size + 1;
   }

   public Integer getTotalPages() {
      if (math.mod(total_size, list_size) > 0) {
         return total_size/list_size + 1;
      } else {
         return (total_size/list_size);
      }
   }
}


Create a new paste based on this one


Comments: