home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / RB3641.ZIP / EX1 / COLLECT2.ST < prev    next >
Text File  |  1990-06-13  |  2KB  |  104 lines

  1.  
  2. "Now, let's create an instance of 
  3.  OrderedCollection:"
  4.  
  5.  
  6. | myOC | 
  7. myOC := OrderedCollection new.
  8.    
  9.  
  10. "Method used to add objects is 'add:'.
  11.  If objects to be added are strings, it can 
  12.  be done as follows ( DoIt) : "
  13.  
  14.  
  15. | myOC |
  16. myOC := OrderedCollection new.
  17. myOC add: 'Some text'.
  18. myOC add: 'And still some more ...'.
  19. myOC add: 'Now that is enough!'.
  20.           
  21.  
  22.  
  23. "To display the contents of your collection
  24.  you can use 'inspect' like this ( DoIt ): "
  25.  
  26.  
  27. | myOC |
  28. myOC := OrderedCollection new.
  29. myOC add: 'Some text'.
  30. myOC add: 'And still some more ...'.
  31. myOC add: 'Now that is enough!'.
  32. myOC inspect.
  33.  
  34. "You can see that by default there are 12
  35.  elements in the collection"
  36.  
  37. "To add something to the first indexposition
  38.  'addFirst' method can be used ( use ShowIt ): "
  39.  
  40.  
  41. | myOC |
  42. myOC := OrderedCollection new.
  43. myOC add: 'Some text'.
  44. myOC add: 'And still some more ...'.
  45. myOC add: 'Now that is enough!'.
  46. myOC addFirst: 'I am the King!!!'.
  47. myOC                                                                        
  48.  
  49.  
  50. "Display the contents of the collection
  51.  sorted alphabetically ( use ShowIt ):"
  52.  
  53.  
  54. | myOC |
  55. myOC := OrderedCollection new.
  56. myOC add: 'Some text'.
  57. myOC add: 'And still some more ...'.
  58. myOC add: 'Now that is enough!'.
  59. myOC addFirst: 'I am the King!!!'.
  60. myOC asSortedCollection.                      
  61.  
  62.  
  63. "Now let's add some integers ( ShowIt ):"
  64.  
  65.  
  66. | myOC |
  67. myOC := OrderedCollection new.
  68. myOC add: 'Some text'.
  69. myOC add: 'And still some more ...'.
  70. myOC add: 'Now that is enough!'.
  71. myOC addFirst: 'I am the King!!!'.
  72. myOC add: 12345.
  73. myOC asSortedCollection. 
  74.  
  75.  
  76. "It seems that strings and integers cannot 
  77.  be sorted by default. You can however define 
  78.  a SortBlock that compares objects just
  79.  the way that you like it. This is implemented
  80.  in To-Do application"
  81.  
  82.  
  83. "Now let's add some OrderedCollections to
  84.  our collection ( use DoIt ):" 
  85.  
  86.  
  87. | myOC |
  88. myOC := OrderedCollection new.
  89. myOC add: 'Some text'.
  90. myOC add: OrderedCollection new.
  91. myOC add: myOC.
  92. myOC inspect.
  93.  
  94.  
  95. "Here we add a string, a new collection
  96.  and ourselves in our collection.
  97.  When you get the first inspect-window,
  98.  doubleclick the contents field so that
  99.  you can really see the contents "
  100.  
  101.  
  102. "*** END OF EXERCISE ***"
  103. 
  104.