SOURCECODE

How to... incorporate a CurrencyFilter on a Currency


Description:
A CurrencyFilter is a Currency itself, in which defined elements are filtered.
(See also: HowTo..incorporate a Currency, HowTo..define a new Currency )
The procedure is very similar to the incorporation of Filters on a Catalog.
This CurrencyFilter could be used in the same way as a normal Currency.

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


Uses:
CurrencyFilter  Currency  CurrencyItem  Catalog  CatalogItem  



SourceCode

// mainly imports
   import data.filters.CurrencyFilter;
   import data.Currency;
   import data.CatalogItem;


 1
// Main Class
   public class MyCurrencyFilter extends CurrencyFilter
   {

    2
   //constructor
      public MyCurrencyFilter(Currency c)
      {
         super(c);
      }

    3
   // this is the core method, in which the filter gets its characteristic
      protected boolean match(CatalogItem ci)
      {
      // all notes and coins less worth than $5 are filtered out
         if ( ((NumberValue)ci.getValue()).getValue().intValue() < 500 )
            return false;
         else
            return true;
      }
   }