WXME0106 ## wxtext wxtab wxmedia wximage  $(lib "comment-snip.ss" "framework")  +(lib "collapsed-snipclass.ss" "framework")   drscheme:sexp-snip   drscheme:syntax-snipclass%  drscheme:number  ,(lib "number-snip.ss" "drscheme" "private")   drscheme:bindings-snipclass%  drscheme:lambda-snip%  drscheme:define-snip%  java-comment-box%  java-interactions-box%  "drscheme:vertical-separator-snip%  wxbad   drscheme:xml-snip  (lib "xml-snipclass.ss" "xml")  drscheme:scheme-snip  "(lib "scheme-snipclass.ss" "xml")  test-case-box%  
text-box%  wxloc     0   K         
ZZ                                                        	Standard  KCourier New         
ZZ                                                          ?       \                              ?      ?      ?      ""   Matching Parenthesis Style   ?       \                              ?      ?      ?      ""      ?                                     ?      ?      ?      &&   (framework:syntax-coloring:scheme:symbol   ?                                     ?      ?      ?      &&   )framework:syntax-coloring:scheme:keyword   ?                                     ?      ?      ?      &&      ?                                     ?      ?      ?      t   )framework:syntax-coloring:scheme:comment   ?                                     ?      ?      ?      t      ?                                     ?      ?      ?      )&   (framework:syntax-coloring:scheme:string   ?                                     ?      ?      ?      ""   *framework:syntax-coloring:scheme:constant   ?                                     ?      ?      ?      ""      ?                                     ?      ?      ?      <$   -framework:syntax-coloring:scheme:parenthesis   ?                                     ?      ?      ?      <$      ?                                     ?      ?      ?      @   'framework:syntax-coloring:scheme:error   ?                                     ?      ?      ?      @      ?                                     ?      ?      ?            'framework:syntax-coloring:scheme:other   ?                                     ?      ?      ?               ?                                     ?      ?      ?      Qp   1drscheme:check-syntax:lexically-bound-identifier   ?                                     ?      ?      ?      Qp      ?                                     ?      ?      ?      D    *drscheme:check-syntax:imported-identifier   ?                                     ?      ?      ?      D    %profj:syntax-coloring:scheme:keyword   ?                                     ?      ?      ?               ?                                     ?      ?      ?      ""   $profj:syntax-coloring:scheme:string   ?                                     ?      ?      ?      ""   %profj:syntax-coloring:scheme:literal   ?                                     ?      ?      ?      ""   %profj:syntax-coloring:scheme:comment   ?                                     ?      ?      ?      t   #profj:syntax-coloring:scheme:error   ?                                     ?      ?      ?      @   (profj:syntax-coloring:scheme:identifier   ?                                     ?      ?      ?      &&   %profj:syntax-coloring:scheme:default   ?                                     ?      ?      ?              F ?             ?      ?      ?      ?      ?      ?            XML  F ?             ?      ?      ?      ?      ?      ?              G ?             ?      ?      ?      ?      ?      ?               ?                                    ?      ?      ?      PP     G ?                                    ?      ?      ?      PP     G ?                                     ?      ?      ?       d       K         ZZ                                                          K-adobe-courier         ZZ                                                          ?                                     ?      ?      ?      **      ?                                     ?      ?      ?              ?                                    ?      ?      ?            G ?                                    ?      ?      ?             KCourier New         
ZZ                                                          ?       ^                              ?      ?      ?              ?                                     ?      ?      ?              ?                                     ?      ?      ?              F         
ZZ                                                                        in  t  e  r  f  a  c  e     I  F  i  l  t  e  r  {  
        /  /     m  e  t  h  o  d     t  h  a  t     s  e  l  e  c  t  s     o  b  j  e  c  t  s     w  i  t  h     s  o  m  e     p  r  o  p  e  r  t  y  
        b  o  o  l  e  a  n     s  e  l  e  c  t  ()  ;  
  }  
  
  in  t  e  r  f  a  c  e     I  F  i  l  t  e  r  2  {  
        /  /     m  e  t  h  o  d     t  h  a  t     s  e  l  e  c  t  s     o  b  j  e  c  t  s     w  i  t  h     s  o  m  e     p  r  o  p  e  r  t  y  
        b  o  o  l  e  a  n     s  e  l  e  c  t  2  (  O  b  j  e  c  t     o  b  j  )  ;  
  }  
  
  
  c  l  a  s  s     C  h  e  a  p  B  o  o  k     i  m  p  l  e  m  e  n  t  s     I  F  i  l  t  e  r  2  {  
        /  /     d  e  t  e  r  m  i  n  e     w  h  e  t  h  e  r     t  h  e     g  i  v  e  n     b  o  o  k     i  s     c  h  e  a  p  
        b  o  o  l  e  a  n     s  e  l  e  c  t  2  (  O  b  j  e  c  t     o  b  j  ){  
              r  e  t  u  r  n     ((  B  o  o  k  )  o  b  j  )  .  p  r  i  c  e     <     1  0  ;  
        }  
  }  
  
  
  c  l  a  s  s     N  e  w  A  u  t  h  o  r     i  m  p  l  e  m  e  n  t  s     I  F  i  l  t  e  r  2  {  
        /  /     d  e  t  e  r  m  i  n  e     w  h  e  t  h  e  r     t  h  e     g  i  v  e  n     b  o  o  k     w  a  s     w  r  i  t  t  e  n     b  y     c  o  n  t  e  m  p  o  r  a  r  y     a  u  t  h  o  r  
        b  o  o  l  e  a  n     s  e  l  e  c  t  2  (  O  b  j  e  c  t     o  b  j  ){  
              r  e  t  u  r  n     (     ((  B  o  o  k  )  o  b  j  )  .  a  u  t  h  o  r  .  i  s  C  o  n  t  e  m  p  o  r  a  r  y  ()     )  ;  
        }  
  }  
  
  
  c  l  a  s  s     B  o  o  k     implem  ents     IFilter  {  
        S  t  r  i  n  g     t  i  t  l  e  ;  
        A  u  t  h  o  r     a  u  t  h  o  r  ;  
        i  n  t     p  r  i  c  e  ;  
  
        B  o  o  k  (  S  t  r  i  n  g     t  i  t  l  e  ,     A  u  t  h  o  r     a  u  t  h  o  r  ,     i  n  t     p  r  i  c  e  )     {  
              t  h  i  s  .  t  i  t  l  e     =     t  i  t  l  e  ;  
              t  h  i  s  .  a  u  t  h  o  r     =     a  u  t  h  o  r  ;  
              t  h  i  s  .  p  r  i  c  e     =     p  r  i  c  e  ;  
        }  
  
        b  o  o  l  e  a  n     e  q  u  a  l  s  (  O  b  j  e  c  t     o  b  j  ){  
              r  e  t  u  r  n              (t  h  i  s  .  t  i  t  l  e  .  e  q  u  a  l  s  (     ((  B  oo  k  )     obj  )  .  title  ))  
                                   &  &     (t  h  i  s  .  a  u  t  h  o  r  .  e  q  u  a  l  s  (     ((  B  oo  k  )     obj  )  .  a  u  t  h  o  r  ))     
                                   &  &     (t  h  i  s  .  p  r  i  c  e     =  =     ((  B  oo  k  )     obj  )  .  p  r  i  c  e  )  ;  
        }  
  
        b  o  o  l  e  a  n     s  e  l  e  c  t  (){  
              r  e  t  u  r  n     t  h  i  s  .  p  r  i  c  e     <     1  0  ;  
        }  
  }  
  
  
  c  l  a  s  s     A  u  t  h  o  r     i  m  p  l  e  m  e  n  t  s     I  F  i  l  t  e  r  {  
        S  t  r  i  n  g     n  a  m  e  ;  
        i  n  t     y  e  a  r  ;  
  
        A  u  t  h  o  r  (  S  tr  i  n  g     n  a  m  e  ,     i  n  t     y  e  a  r  ){  
              t  h  i  s  .  n  a  m  e     =     n  a  m  e  ;  
              t  h  i  s  .  y  e  a  r     =     y  e  a  r  ;  
        }  
  
        b  o  o  l  e  a  n     e  q  u  a  l  s  (  O  b  j  e  c  t     o  b  j  )     {  
              r  e  t  u  r  n              (t  h  i  s  .  n  a  m  e  .  e  q  u  a  l  s  (      ((  Au  tho  r  )     ob  j  )  .  n  ame     ))  
                                   &  &     (t  h  i  s  .  y  e  ar     =  =     (      ((  Au  tho  r  )     ob  j  )  .  y  e  a  r     ))  ;  
        }  
  
        b  o  o  l  e  a  n     s  e  l  e  c  t  (){  
              r  e  t  u  r  n     t  h  i  s  .  y  e  a  r     >     1  9  4  0  ;  
        }  
  
        /  /     d  e  t  e  r  m  i  n  e     w  h  e  t  h  e  r  i     t  h  i  s     i  s     a     c  o  n  t  e  m  p  o  r  a  r  y     a  u  t  h  o  r  
        b  o  o  l  e  a  n     i  s  C  on  te  m  p  o  r  a  r  y  (){  
              r  e  t  u  r  n     t  h  i  s  .  y  e  a  r     >     1  9  4  0  ;  
        }  
  }  
  
  
  a  b  s  t  r  a  c  t     c  l  a  s  s     A  L  o  O  b  j  {  
  
        /  /     c  o  u  n  t     t  h  e     n  u  m  b  e  r     o  f     i  t  e  m  s     i  n     t  h  i  s     l  i  s  t  
        a  b  s  t  r  a  c  t     int     count  ()  ;  
  
        /  /     d  e  t  e  r  m  i  n  e     w  h  e  t  h  e  r     t  h  i  s     l  i  s  t     c  o  n  t  a  i  n  s     t  h  e     g  i  v  e  n     o  b  j  e  c  t  
        a  b  s  t  r  a  c  t     b  o  o  l  e  a  n     co  ntains  (  O  b  j  e  c  t     ob  j  )  ;  
  
        /  /     r  e  m  o  v  e     t  h  e     f  i  r  s  t     o  c  c  u  r  r  e  n  c  e     o  f     t  h  e     g  i  v  e  n     o  b  j  e  c  t     f  r  o  m     t  h  i  s     l  i  s  t  
        a  b  s  t  r  a  c  t     A  L  o  O  b  j     r  e  m  o  v  e  (  O  b  j  e  c  t     o  b  j  )  ;  
  
        /  /     d  e  t  e  r  m  i  n  e     w  h  e  t  h  e  r     t  h  e  r  e     i  s     a     '  s  e  l  e  c  t  e  d  '     o  b  j  e  c  t     i  n     t  h  i  s     l  i  s  t  
        a  b  s  t  r  a  c  t     b  o  o  l  e  a  n     o  r  M  a  p  ()  ;  
  
        /  /     d  e  t  e  r  m  i  n  e     w  h  e  t  h  e  r     t  h  e  r  e     i  s     a     '  s  e  l  e  c  t  e  d  '     o  b  j  e  c  t     i  n     t  h  i  s     l  i  s  t  
        a  b  s  t  r  a  c  t     b  o  o  l  e  a  n     o  r  M  a  p  2  (  I  F  i  l  t  e  r  2     f  i  l  t  e  r  )  ;  
  }  
  
  
  c  l  a  s  s     M  T  L  o  Ob  j     exte  nd  s     AL  oObj  {  
  
        M  T  L  o  O  b  j  (){     }  
  
        i  n  t     c  o  u  n  t  (){     r  e  t  u  r  n     0  ;     }  
  
        b  o  o  l  e  a  n     c  o  n  t  a  i  n  s  (  O  b  j  e  c  t     o  b  j  ){     r  e  t  u  r  n     f  a  l  s  e  ;     }  
  
        A  L  o  O  b  j     r  e  m  o  v  e  (  O  b  j  e  c  t     o  b  j  ){     r  e  t  u  r  n     t  h  i  s  ;     }  
  
        b  o  o  l  e  a  n     o  r  M  a  p  (){     r  e  t  u  r  n     f  a  l  s  e  ;     }  
  
        b  o  o  l  e  a  n     o  r  M  a  p  2  (  I  F  i  l  t  e  r  2     f  i  l  t  e  r  ){     r  e  t  u  r  n     f  a  l  s  e  ;     }  
  
  }  
  
  
  c  l  a  s  s     C  o  n  s  L  o  O  b  j     exte  nd  s     AL  oObj  {  
        O  b  j  e  c  t     f  s  t  ;  
        A  L  o  O  b  j     r  s  t  ;  
  
        C  o  n  s  L  o  O  b  j  (  O  b  j  e  c  t     f  s  t  ,     A  L  o  O  b  j     r  s  t  ){  
              t  h  i  s  .  f  s  t     =     f  s  t  ;  
              t  h  i  s  .  r  s  t     =     r  s  t  ;  
        }  
  
             	Template:  
  ...this.fst...  
  ...this.rst...  
  ...this.count()...  
  ...this.contains(Object obj)...  
  ...this.remove(Object obj)...  
  ...this.rst.orMap()...       
  
        i  n  t     c  o  u  n  t  ()     {     
              r  e  t  u  r  n     1     +     t  h  i  s  .  r  s  t  .  c  o  u  n  t  ()  ;  
        }  
  
        b  o  o  l  e  a  n     c  o  n  t  a  i  n  s  (  O  b  j  e  c  t     o  b  j  ){  
              r  e  t  u  r  n              (t  h  i  s  .  f  s  t  .  e  q  u  a  l  s  (  o  b  j  ))  
                                   |  |     (t  hi  s  .  r  s  t  .  c  o  n  t  a  i  n  s  (  o  b  j  ))  ;  
        }  
  
        A  L  o  O  b  j     r  e  m  o  v  e  (  O  b  j  e  c  t     o  b  j  ){  
              i  f     (t  h  i  s  .  f  s  t  .  e  q  u  a  l  s  (  o  b  j  ))  
                    r  e  t  u  r  n     t  h  i  s  .  r  s  t  ;  
              e  l  s  e  
                    r  e  t  u  r  n     n  e  w     C  o  n  s  L  o  O  b  j  (t  h  i  s  .  f  s  t  ,     t  h  i  s  .  r  s  t  .  r  e  m  o  v  e  (  o  b  j  ))  ;  
        }  
  
        b  o  o  l  e  a  n     o  r  M  a  p  (){  
              r  e  t  u  r  n              (     ((  I  F  i  l  t  e  r  )(t  h  i  s  .  f  s  t  ))  .  s  e  l  e  c  t  ()     )  
                                   |  |     (t  h  i  s  .  r  s  t  .  o  r  M  a  p  ())  ;  
        }  
  
        b  o  o  l  e  a  n     o  r  M  a  p  2  (  I  F  i  l  t  e  r  2     f  i  l  t  e  r  ){  
              r  e  t  u  r  n            fi  l  t  e  r  .  s  e  l  e  c  t  2  (t  h  i  s  .  f  s  t  )  
                                   |  |     (t  h  i  s  .  r  s  t  .  o  r  M  a  p  2  (  f  i  l  t  e  r  ))  ;  
        }  
  }  
  
            
"Examples"  
  
  Author     mf     =     new     Author  (  
"Matthias"  ,     1958  )  ;  
  
  Author     bard     =     new     Author  (  "Shakespeare"  ,     1716  )  ;  
  
  Book     b1     =     new     Book     (  "HtDP"  ,     mf  ,     60  )  ;  
  
  Book     b2     =     new     Book     (  "LL"  ,     mf  ,     18  )  ;  
  
  Book     b3     =     new     Book     (  "Hamlet"  ,     bard  ,     7  )  ;  
  
  ALoObj     mtlist     =     new     MTLoObj  ()  ;     
  
  ALoObj     list1     =     new     	ConsLoObj  (  b1  ,     new     	ConsLoObj  (  b2  ,     mtlist  ))  ;  
  
  ALoObj     list2     =     new     	ConsLoObj  (  b3  ,     list1  )  ;  
  
  
  /"Testing the count() method in class ListofObj"  
  
  mtlist  .  count  ()     ==     0  
  
  list1  .  count  ()     ==     2  
  
  list2  .  count  ()     ==     3  
  
  2"Testing the contains() method in class ListofObj"  
  
  mtlist  .  contains  (  b1  )     ==     false  
  
  list1  .  contains  (  b3  )     ==     false  
  
  list2  .  contains  (  b3  )     ==     true  
  
  list2  .  contains  (  b2  )     ==     true  
  
  0"Testing the remove() method in class ListofObj"  
  
  mtlist  .  remove  (  b1  )  .  equals  (  mtlist  )  
  
  list1  .  remove  (  b3  )  .  count  ()  
  
  list2  .  remove  (  b3  )  .  count  ()  
  
  '"Testing select() method in class Book"  
  
  b1  .  select  ()     ==   false  
  
  b2  .  select  () ==   true  
  
  )"Testing select() method in class Author"  
  
  mf  .  select  ()     ==   true  
  
  bard  .  select  () ==   false  
  
  *"Testing orMap() method on lists of books"  
  
  mtlist  .  orMap  () ==   false  
  
  list1  .  orMap  ()     ==   false  
  
  list2  .  orMap  ()     ==   true  
  
  CheapBook cheapFilter   = new   	CheapBook  ()  ;  
  
  mtlist  .  orMap2  (  cheapFilter  ) ==   false  
  
  list1  .  orMap2  (  cheapFilter  ) ==   false  
  
  list2  .  orMap2  (  cheapFilter  ) ==   true  
  
  NewAuthor authorFilter   = new   	NewAuthor  ()  ;  
  
  mtlist  .  orMap2  (  authorFilter  ) ==   false  
  
  list1  .  orMap2  (  authorFilter  ) ==   true  
  
  list2  .  orMap2  (  authorFilter  ) ==   true  
       
  
  
   G        Q Examples  
  
  (Author mf = new Author("Matthias" 1958);  
  .Author bard = new Author("Shakespeare", 1716);  
  
  &Book b1 = new Book ("HtDP", mf, 2001);  
  $Book b2 = new Book ("LL", mf, 1974);  
  *Book b3 = new Book ("Hamlet", bard, 1736);  
  
  ALoObj mtlist = new MTLoObj();   
  <ALoObj list1 = new ConsLoObj(b1, new ConsLoObj(b2, mtlist));  
  )ALoObj list2 = new ConsLoObj(b3, mtlist);  
  
  /"Testing the count() method in class ListofObj"  
  mtlist.count() == 0;  
  list1.count() == 2;  
  list2.count() == 3;  
  
  2"Testing the contains() method in class ListofObj"  
  mtlist.contains(b1) == false;  
  list1.contains(b3) == false;  
  list2.contains(b3) == true  
  list2.contains(b2) == true;  
  
  0"Testing the remove() method in class ListofObj"  
  !mtlist.remove(b1).equals(mtlist);  
  !list1.remove(bard).equals(list1);  
  list2.remove(b3).equals(list1);  
  
  NewAuthor authorFilter   = new   	NewAuthor  ()  ;  
  mtlist  .  orMap2  (  authorFilter  ) ==   false  
  list1  .  orMap2  (  authorFilter  ) ==   true  
  list2  .  orMap2  (  authorFilter  ) ==   true  
          
