home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rox.zip / collect.rox < prev    next >
Text File  |  1993-08-28  |  2KB  |  80 lines

  1. :*------------------------------------------------------------------
  2. :* REXX Object eXtensions : collection class
  3. :*------------------------------------------------------------------
  4.  
  5. :class collection
  6.  
  7. :*------------------------------------------------------------------
  8. :* methods that need to be overridden
  9. :*------------------------------------------------------------------
  10. :method atIndex
  11.    parse source . . me .
  12.    say me ": for object of class" RoxClass(self)
  13.    say me ": this method needs to be overriden in a subclass"
  14.    return self
  15.  
  16. :method size
  17.    parse source . . me .
  18.    say me ": for object of class" RoxClass(self)
  19.    say me ": this method needs to be overriden in a subclass"
  20.    return self
  21.  
  22. :*------------------------------------------------------------------
  23. :* return boolean indicating whether given item is found in the
  24. :* collection
  25. :*------------------------------------------------------------------
  26. :method includes
  27.    test = arg(1)
  28.  
  29.    if ("string" = RoxClass(test)) then
  30.       string = 1
  31.    else
  32.       string = 0
  33.  
  34.    do i = 1 to .size(self)
  35.       item = .atIndex(self,i)
  36.  
  37.       if string then
  38.          bool = (test = item)
  39.       else
  40.          bool = .equal(test,item)
  41.  
  42.       if (bool) then
  43.          return 1
  44.    end
  45.  
  46.    return 0
  47.  
  48. :*------------------------------------------------------------------
  49. :* walk over items in the collection, executing code
  50. :*
  51. :* .do(obj,var,code<,init<,term>>)
  52. :*    var  - variable to set to the current item in the collection
  53. :*    code - code to execute for each item - variable 'var' (above)
  54. :*           will be set to the value of the current item
  55. :*    init - code to run before walking collection
  56. :*    term - code to run after walking collection
  57. :*------------------------------------------------------------------
  58. :method do
  59.    !!var  = arg(1)
  60.    !!code = arg(2)
  61.  
  62.    !!size = .size(self)
  63.    !!self = self
  64.  
  65.    result = ""
  66.  
  67.    if (arg() >= 3) & (arg(3) <> "") then
  68.       interpret arg(3)
  69.  
  70.    do !!i = 1 to !!size
  71.       !!item = .atIndex(!!self,!!i)
  72.  
  73.       interpret !!var "= !!item;" !!code
  74.    end
  75.  
  76.    if (arg() >= 4) & (arg(4) <> "") then
  77.       interpret arg(4)
  78.  
  79.    return result
  80.