Interval.st
branchjv
changeset 17732 a1892eeca6c0
parent 17711 39faaaf888b4
child 17761 b0e5971141bc
equal deleted inserted replaced
17731:295728e8f410 17732:a1892eeca6c0
   537         ^ 0
   537         ^ 0
   538     ].
   538     ].
   539     ^ stop - start // step + 1
   539     ^ stop - start // step + 1
   540 ! !
   540 ! !
   541 
   541 
       
   542 !Interval methodsFor:'set operations'!
       
   543 
       
   544 intersect:aCollection
       
   545     "return a new interval containing all elements of the receiver, 
       
   546      which are also contained in the argument collection"
       
   547 
       
   548     "/ could be much more intelligent here...
       
   549     aCollection class == Interval ifTrue:[
       
   550         aCollection step = step ifTrue:[
       
   551             step = 1 ifTrue:[
       
   552                 (self includes:aCollection start) ifTrue:[
       
   553                     ^ (start max:(aCollection start)) to:(stop min:(aCollection stop))
       
   554                 ].
       
   555                 (self includes:aCollection stop) ifTrue:[
       
   556                     ^ (start max:(aCollection start)) to:(stop min:(aCollection stop))
       
   557                 ]
       
   558             ]
       
   559         ].
       
   560     ].
       
   561 
       
   562     ^ super intersect:aCollection
       
   563 
       
   564     "
       
   565      (1 to:10) intersect:(4 to:20)      
       
   566      (1 to:10) intersect:(11 to:20)      
       
   567      (1 to:10) intersect:(10 to:20)      
       
   568      (4 to:20) intersect:(1 to:10)      
       
   569      (4 to:20) intersect:(1 to:10 by:2)      
       
   570     "
       
   571 ! !
       
   572 
   542 !Interval methodsFor:'sorting & reordering'!
   573 !Interval methodsFor:'sorting & reordering'!
   543 
   574 
   544 reversed
   575 reversed
   545     "return a copy with elements in reverse order"
   576     "return a copy with elements in reverse order"
   546 
   577 
   583 ! !
   614 ! !
   584 
   615 
   585 !Interval methodsFor:'testing'!
   616 !Interval methodsFor:'testing'!
   586 
   617 
   587 includes:anElement
   618 includes:anElement
       
   619     "return true if anElement is in the interval (Numeric compare using =)"
       
   620 
   588     |rest|
   621     |rest|
       
   622 
   589     stop >= start ifTrue:[
   623     stop >= start ifTrue:[
   590         (anElement between:start and:stop) ifFalse:[^ false].
   624         (anElement between:start and:stop) ifFalse:[^ false].
   591     ] ifFalse:[
   625     ] ifFalse:[
   592         (anElement between:stop and:start) ifFalse:[^ false].
   626         (anElement between:stop and:start) ifFalse:[^ false].
   593     ].
   627     ].
   599      (1 to:15) includes:16
   633      (1 to:15) includes:16
   600      (1 to:15) includes:1    
   634      (1 to:15) includes:1    
   601      (1 to:15) includes:15   
   635      (1 to:15) includes:15   
   602      (1 to:15) includes:5    
   636      (1 to:15) includes:5    
   603      (1 to:15) includes:14   
   637      (1 to:15) includes:14   
       
   638      (1 to:15) includes:4   
   604      (1 to:15) includes:4.0   
   639      (1 to:15) includes:4.0   
   605      (1 to:15) includes:4.4   
   640      (1 to:15) includes:4.4   
   606 
   641 
   607      (1 to:15 by:3) includes:0
   642      (1 to:15 by:3) includes:0
   608      (1 to:15 by:3) includes:16
   643      (1 to:15 by:3) includes:16
   648 ! !
   683 ! !
   649 
   684 
   650 !Interval class methodsFor:'documentation'!
   685 !Interval class methodsFor:'documentation'!
   651 
   686 
   652 version
   687 version
   653     ^ '$Id: Interval.st 10447 2009-06-14 13:09:55Z vranyj1 $'
   688     ^ '$Id: Interval.st 10473 2009-10-24 15:48:19Z vranyj1 $'
   654 ! !
   689 ! !
       
   690