Save This Page
Home » displaytag-1.1.1-src » org » displaytag » sample » [javadoc | source]
    1   /**
    2    * Licensed under the Artistic License; you may not use this file
    3    * except in compliance with the License.
    4    * You may obtain a copy of the License at
    5    *
    6    *      http://displaytag.sourceforge.net/license.html
    7    *
    8    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
    9    * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   10    * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   11    */
   12   package org.displaytag.sample;
   13   
   14   import java.util.ArrayList;
   15   import java.util.Random;
   16   
   17   
   18   /**
   19    * Just a utility class for testing out the table and column tags. When this class is created, it loads itself with a
   20    * number of ListObjects that are shown throughout the various example pages that exercise the table object. If created
   21    * via the default constructor, this loads itself with 60 ListObjects.
   22    * @author epesh
   23    * @author Fabrizio Giustina
   24    * @version $Revision$ ($Author$)
   25    */
   26   public class TestList extends ArrayList
   27   {
   28   
   29       /**
   30        * D1597A17A6.
   31        */
   32       private static final long serialVersionUID = 899149338534L;
   33   
   34       /**
   35        * Creats a TestList that is filled with 60 ListObjects suitable for testing.
   36        */
   37       public TestList()
   38       {
   39           super();
   40   
   41           for (int j = 0; j < 60; j++)
   42           {
   43               add(new ListObject());
   44           }
   45       }
   46   
   47       /**
   48        * Creates a TestList that is filled with [size] ListObjects suitable for testing.
   49        * @param size int size of the list
   50        * @param duplicates boolean put duplicates in the list
   51        */
   52       public TestList(int size, boolean duplicates)
   53       {
   54           if (duplicates)
   55           {
   56               // generate a random number between 1 and 3 and duplicate that many number of times.
   57               for (int j = 0; j < size; j++)
   58               {
   59   
   60                   ListObject object1 = new ListObject();
   61                   ListObject object2 = new ListObject();
   62                   ListObject object3 = new ListObject();
   63   
   64                   int random = new Random().nextInt(3);
   65                   for (int k = 0; k <= random; k++)
   66                   {
   67                       add(object1);
   68                   }
   69   
   70                   object1.setId(object2.getId());
   71   
   72                   random = new Random().nextInt(3);
   73                   for (int k = 0; k <= random; k++)
   74                   {
   75                       add(object1);
   76                       add(object2);
   77                   }
   78   
   79                   object1.setEmail(object3.getEmail());
   80   
   81                   random = new java.util.Random().nextInt(3);
   82                   for (int k = 0; k <= random; k++)
   83                   {
   84                       add(object1);
   85                   }
   86               }
   87           }
   88           else
   89           {
   90               for (int j = 0; j < size; j++)
   91               {
   92                   add(new ListObject());
   93               }
   94           }
   95       }
   96   
   97       /**
   98        * Returns a ListObject using get(index) from the Array.
   99        * @param index int index of the List object into the array
  100        * @return ListObject
  101        */
  102       public ListObject getItem(int index)
  103       {
  104           return (ListObject) super.get(index);
  105       }
  106   
  107   }

Save This Page
Home » displaytag-1.1.1-src » org » displaytag » sample » [javadoc | source]