SOURCECODE

How to... incorporate a CatalogFilter on a Catalog


Description:
A CatalogFilter is a Catalog itself, in which defined elements are filtered.
(See also: HowTo..incorporate a Catalog, HowTo..define a CatalogItem )
This CatalogFilter could be used in the same way as a normal Catalog.

ToDo's:
  1. Incorporate a subclass of abstract CatalogFilter.
  2. Add constructors to set the Filters name and attributes.
  3. Implement protected boolean match(CatalogItem ci).
    This method determines for each CatalogItem, whether it will be in the CatalogFilter or not.
  4. Make an instance of your CatalogFilter, where it is to be used.
    (Ex.: MyCatalogFilter mcf = new MyCatalogFilter(Catalog cToBeFiltered) )
    Use it instead of the source catalog, where you only want the unfiltered items.


Uses:
CatalogFilter  Catalog  CatalogItem  



SourceCode

// mainly imports
   import data.filters.CatalogFilter;
   import data.Catalog;
   import data.CatalogItem;

 1
// Main Class
   public class MyCatalogFilter extends CatalogFilter
   {

    2
   // Constructor
      public MyCatalogFilter(Catalog cOrg)
      {
         super(cOrg);
      }

    3
   // this is the core method, in which the filter gets its characteristic
      protected boolean match(CatalogItem ci)
      {
         if (ci.getName().equals("Item which is unfiltered"))
            return true;
         else
            return false;
      }

   }