Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. displayWithDisplayOrder: anArray in: aCollection
  2.     | dictKeyIndex keys printedKeys currentKey index aBoolean |
  3.    
  4.     dictKeyIndex := Dictionary new.
  5.     1 to: anArray size do: [ :cpt | dictKeyIndex at: (anArray at: cpt) key put: cpt ].
  6.     keys := dictKeyIndex keys.
  7.    
  8.     currentKey := displayOrder at: (index := 1).
  9.     aBoolean := displayOrder includes: #*.
  10.    
  11.     aBoolean
  12.         ifFalse: [ keys do: [ :each | aCollection addAll: (anArray at: (dictKeyIndex at: each)) value ] ]
  13.         ifTrue: [
  14.             "Before the * wildcard"
  15.             [ currentKey ~= '*' ]
  16.                 whileTrue: [
  17.                     (keys includes: currentKey)
  18.                         ifTrue: [
  19.                             aCollection addAll: (anArray at: (dictKeyIndex at: currentKey)) value.
  20.                             keys remove: currentKey ].
  21.                     currentKey := displayOrder at: (index := index + 1) ]
  22.            
  23.             "The * wildcard"
  24.             printedKeys := OrderedCollection new.
  25.             keys
  26.                 do: [ :each |
  27.                     (displayOrder includes: each)
  28.                         ifFalse: [
  29.                             aCollection addAll: (anArray at: (dictKeyIndex at: each)) value.
  30.                             printedKeys add: each ] ].
  31.             keys := keys select: [ :each | (printedKeys includes: each) not ]
  32.                
  33.             "After the * wildcard"
  34.             index := index + 1.
  35.             [ index > displayOrder size ]
  36.                 whileFalse: [
  37.                     currentKey := displayOrder at: index.
  38.                     (keys includes: currentKey)
  39.                         ifTrue: [ aCollection addAll: (anArray at: (dictKeyIndex at: currentKey)) value ].
  40.                     index := index + 1 ] ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement