List.st
author Stefan Vogel <sv@exept.de>
Wed, 11 Apr 2018 14:20:52 +0200
changeset 4632 78bc0134bc30
parent 4147 c68cc70f3d77
child 4683 dfcc81b5bc10
permissions -rw-r--r--
#REFACTORING by stefan class: List changed: #removeFirstIfAbsent:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1996 by eXept Software AG
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
    13
3836
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
    14
"{ NameSpace: Smalltalk }"
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
    15
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
OrderedCollection subclass:#List
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:'dependents'
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'Collections-Sequenceable'
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!List class methodsFor:'documentation'!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 1996 by eXept Software AG
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
documentation
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
737
c76130b05afb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 673
diff changeset
    42
    Lists are mostly like OrderedCollections, but keep their dependents
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    locally (which is adding a bit of performance - not functionality).
737
c76130b05afb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 673
diff changeset
    44
    In addition, special change notifications are emitted, whenever
c76130b05afb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 673
diff changeset
    45
    a lists contents is changed.
c76130b05afb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 673
diff changeset
    46
    Some views (SelectionIn*View and DataSetView) react specially on
3968
590c6d311872 #DOCUMENTATION by mawalch
mawalch
parents: 3836
diff changeset
    47
    those messages and perform optimized updates.
737
c76130b05afb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 673
diff changeset
    48
    (the change messages pass the range-of-change as parameter).
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    In ST/X, most functionality is already provided by OrderedCollection,
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    so there is not much new stuff found here.
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    It has been mostly provided, for ST-80 compatibility,
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    where it adds sorting capabilities.
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
4147
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    55
    [caveat:]
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    56
        'List' is probably a bad name, which may confuse beginners.
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    57
        I have nothing in common with LinkedLists.
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    58
        Instances are just regular ordered collections, with the added benefit of
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    59
        sending out information about changes.
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    60
        Thus, they can be used as a model of textviews or selection list views,
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    61
        which need to redraw whenever the contents of the list changes.
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    62
        (and Lists not only send out change notifications when modified,
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    63
         but also include information about the range of changed elements.
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    64
         So the view can optimize its redraws)
c68cc70f3d77 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4089
diff changeset
    65
        
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    [see also:]
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
        Array OrderedCollection
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    [author:]
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
        Claus Gittinger
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
! !
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
!List methodsFor:'accessing'!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
    76
at:anIndex put:anObject
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
    77
    "set the element at index, to be anIndex.
608
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    78
     Return anObject (sigh).
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    79
     In contrast to OrderedCollection, Lists allow putting an object
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    80
     right after the last element and auto-grow in this case;
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    81
     however, putting 2 or more indices after the last element is 
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    82
     reported as an error."
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    83
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    84
    |idx "{ Class: SmallInteger }"|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
    85
608
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    86
    idx := anIndex + firstIndex - 1.
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    87
    ((anIndex < 1) or:[idx > lastIndex]) ifTrue:[
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    88
        idx == (lastIndex+1) ifTrue:[
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    89
            self makeRoomAtLast.
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    90
            lastIndex := lastIndex + 1.
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    91
        ] ifFalse:[
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    92
            ^ self subscriptBoundsError:anIndex
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    93
        ]
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    94
    ].
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    95
    
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
    96
    contentsArray basicAt:idx put:anObject.
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
    97
    dependents size ~~ 0 ifTrue:[self changed:#at: with:anIndex].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
    98
    ^ anObject
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
    99
608
d7a0efe4105f allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents: 606
diff changeset
   100
    "Modified: / 28.1.1998 / 16:44:49 / cg"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   101
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   102
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   103
list
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   104
    ^ self
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   105
! !
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   106
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   107
!List methodsFor:'adding & removing'!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   108
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   109
add:anObject
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   110
    "add the argument, anObject to the end of the collection
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   111
     Return the argument, anObject."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   112
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   113
    super add:anObject.
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   114
    dependents notNil ifTrue:[self changed:#insert: with:(self size)].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   115
    ^ anObject
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   116
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   117
    "Modified: / 29.1.1998 / 10:52:32 / cg"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   118
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   119
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   120
add:anObject beforeIndex:index
1922
be14f1a04953 #add:beforeIndex: - make immune against redefinition of #add: using
Stefan Vogel <sv@exept.de>
parents: 1916
diff changeset
   121
    "add the argument, anObject to the end of the collection.
be14f1a04953 #add:beforeIndex: - make immune against redefinition of #add: using
Stefan Vogel <sv@exept.de>
parents: 1916
diff changeset
   122
     Return the receiver (sigh - ST-80 compatibility)."
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   123
1922
be14f1a04953 #add:beforeIndex: - make immune against redefinition of #add: using
Stefan Vogel <sv@exept.de>
parents: 1916
diff changeset
   124
    super add:anObject beforeIndex:index.
613
bc304634b22d fixed change-message
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   125
    dependents notNil ifTrue:[self changed:#insert: with:index].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   126
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   127
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   128
addAll:aCollection beforeIndex:index
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   129
    "insert all elements of the argument
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   130
     Return the receiver."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   131
2991
29a4cc9c2a0b class: List
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   132
    super addAll:aCollection beforeIndex:index.
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   133
    dependents notNil ifTrue:[
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   134
        self changed: #insertCollection: with:(Array with:index with:(aCollection size))
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   135
    ]
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   136
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   137
909
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   138
addAll:aCollection from:startIndex to:endIndex beforeIndex:index
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   139
    "insert elements start to stop from the argument
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   140
     Return the receiver."
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   141
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   142
    |count idx|
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   143
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   144
    count := endIndex - startIndex + 1.
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   145
    idx := self makeRoomAtIndex:(index + firstIndex - 1) for:count.
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   146
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   147
    aCollection isSequenceable ifTrue:[
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   148
        "/ we are lucky - that thing can count & do bulk copies
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   149
        "/ notice: the above may change firstIndex
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   150
        contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:startIndex.
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   151
    ] ifFalse:[
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   152
        self error:'collection must be sequenceable'
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   153
    ].
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   154
    dependents notNil ifTrue:[
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   155
        self changed: #insertCollection: with:(Array with:index with:count)
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   156
    ]
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   157
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   158
    "Modified: / 29.1.1998 / 10:52:57 / cg"
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   159
!
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   160
1142
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   161
addAllLast:aCollection
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   162
    "add all elements of the argument, aCollection to the end of the collection.
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   163
     Return the argument, aCollection."
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   164
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   165
    self addAll:aCollection beforeIndex:self size + 1.
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   166
    ^ aCollection
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   167
!
8b91f129aea7 addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   168
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   169
addFirst:anObject
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   170
    "add the argument, anObject to the beginning of the collection.
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   171
     Return the argument, anObject."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   172
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   173
    super addFirst:anObject.
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   174
    dependents notNil ifTrue:[self changed:#insert: with:1].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   175
    ^ anObject
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   176
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   177
    "Modified: / 29.1.1998 / 10:53:09 / cg"
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   178
!
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   179
632
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   180
clearContents
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   181
    "remove all elements from the collection but keep the contentsArray.
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   182
     Useful for huge lists, if the contents will be rebuild soon (using #add:) 
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   183
     to a size which is similar to the lists current size.
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   184
     Returns the receiver."
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   185
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   186
     |prevSize|
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   187
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   188
     prevSize := self size.
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   189
     super clearContents.
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   190
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   191
     prevSize ~~ 0 ifTrue:[
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   192
        dependents notNil ifTrue:[
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   193
            self changed:#removeFrom: with:(Array with:1 with:prevSize)
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   194
        ]
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   195
     ]
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   196
!
7008f9f8ad20 added #clearContents:
ca
parents: 613
diff changeset
   197
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   198
removeAll
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   199
    "remove all elements from the collection.
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   200
     Returns the receiver."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   201
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   202
     |prevSize|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   203
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   204
     prevSize := self size.
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   205
     super removeAll.
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   206
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   207
     prevSize ~~ 0 ifTrue:[
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   208
        dependents notNil ifTrue:[
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   209
            self changed:#removeFrom: with:(Array with:1 with:prevSize)
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   210
        ]
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   211
     ]
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   212
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   213
    "Modified: / 29.1.1998 / 10:53:28 / cg"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   214
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   215
3301
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   216
removeAllSuchThat:aBlock
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   217
    "remove all elements that meet a test criteria as specified in aBlock.
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   218
     The argument, aBlock is evaluated for successive elements and all those,
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   219
     for which it returns true, are removed.
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   220
     Destructive: modifies the receiver.
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   221
     Return a collection containing the removed elements."
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   222
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   223
    |removedElements|
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   224
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   225
    removedElements := super removeAllSuchThat:aBlock.
3836
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
   226
    removedElements notEmpty ifTrue:[
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
   227
        self changed.
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
   228
    ].
3301
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   229
    ^ removedElements.
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   230
!
8a86b5083cf5 class: List
Claus Gittinger <cg@exept.de>
parents: 2999
diff changeset
   231
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   232
removeFirst
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   233
    "remove the first element from the collection; return the element."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   234
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   235
     |deletedObject|
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   236
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   237
     deletedObject := super removeFirst.
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   238
     dependents notNil ifTrue:[self changed:#remove: with:1].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   239
     ^ deletedObject
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   240
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   241
    "Modified: / 29.1.1998 / 10:53:36 / cg"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   242
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   243
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   244
removeFirst:n
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   245
    "remove the first n elements from the collection; 
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   246
     Return a collection containing the removed elements."
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   247
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   248
    |deletedObjects|
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   249
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   250
    deletedObjects := super removeFirst:n.
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   251
    dependents notNil ifTrue:[self changed:#removeFrom: with:(Array with:1 with:n)].
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   252
    ^ deletedObjects
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   253
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   254
    "Modified: / 29.1.1998 / 10:53:40 / cg"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   255
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   256
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   257
removeFirstIfAbsent:exceptionBlock
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   258
    "remove the first element from the collection; return the element.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   259
     If there is no element in the receiver collection, return the value from
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   260
     exceptionBlock."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   261
4632
78bc0134bc30 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4147
diff changeset
   262
    self notEmpty ifTrue:[ ^ self removeFirst ].
1778
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   263
    ^ exceptionBlock value
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   264
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   265
    "Modified: / 21-10-2006 / 23:03:46 / cg"
4632
78bc0134bc30 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4147
diff changeset
   266
    "Modified: / 11-04-2018 / 11:52:30 / stefan"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   267
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   268
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   269
removeFromIndex:startIndex toIndex:stopIndex
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   270
    "remove the elements stored under startIndex up to and including
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   271
     the elements under stopIndex.
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   272
     Return the receiver.
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   273
     Returning the receiver here is a historic leftover - it may change."
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   274
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   275
    |ret|
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   276
2004
e9ee1c2930b0 dont send out change-notifications, if there was no change
ab
parents: 1922
diff changeset
   277
    stopIndex < startIndex ifTrue:[^ self].
e9ee1c2930b0 dont send out change-notifications, if there was no change
ab
parents: 1922
diff changeset
   278
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   279
    ret := super removeFromIndex:startIndex toIndex:stopIndex.
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   280
    dependents notNil ifTrue:[
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   281
        self changed:#removeFrom: with:(Array with:startIndex with:stopIndex).
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   282
    ].
742
e750820e9f1d comment
Claus Gittinger <cg@exept.de>
parents: 737
diff changeset
   283
    ^ ret
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   284
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   285
    "Modified: / 29.1.1998 / 10:54:03 / cg"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   286
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   287
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   288
removeIdentical:anObject ifAbsent:exceptionBlock
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   289
    "remove the first element which is identical to anObject;
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   290
     if found, remove and return it; 
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   291
     if not, return the value from evaluating exceptionBlock.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   292
     Uses identity compare (==) to search for the element."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   293
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   294
    |index|
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   295
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   296
    index := self identityIndexOf:anObject.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   297
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   298
    index == 0 ifTrue:[ ^ exceptionBlock value ].
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   299
    self removeFromIndex:index toIndex:index.
1778
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   300
    ^ anObject
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   301
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   302
    "Modified: / 21-10-2006 / 23:03:29 / cg"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   303
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   304
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   305
removeLast
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   306
    "remove the last element from the collection; return the element"
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   307
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   308
     |deletedObject|
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   309
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   310
     deletedObject :=  super removeLast.
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   311
     dependents notNil ifTrue:[self changed:#remove: with:(1 + self size)].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   312
     ^ deletedObject
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   313
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   314
    "Modified: / 29.1.1998 / 10:54:15 / cg"
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   315
!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   316
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   317
removeLast:n
2054
c78f3c579b5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
   318
    "remove the last n elements from the receiver collection. 
c78f3c579b5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
   319
     Return a collection of removed elements."
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   320
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   321
    |deletedObjects stop|
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   322
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   323
    stop := self size.
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   324
    deletedObjects := super removeLast:n.
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   325
    dependents notNil ifTrue:[
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   326
        self changed:#removeFrom: with:(Array with:(stop - n + 1) with:stop).
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   327
    ].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   328
    ^ deletedObjects
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   329
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   330
    "Modified: / 29.1.1998 / 10:54:25 / cg"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   331
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   332
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   333
removeLastIfAbsent:exceptionBlock
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   334
    "remove the last element from the collection; return the element.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   335
     If there is no element in the receiver collection, return the value from
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   336
     exceptionBlock."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   337
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   338
    self size > 0 ifTrue:[ ^ self removeLast ].
1778
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   339
    ^ exceptionBlock value
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   340
1fc313500385 ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
   341
    "Modified: / 21-10-2006 / 23:03:53 / cg"
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   342
!
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   343
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   344
reset
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   345
    "logically remove all elements from the collection.
4089
43143bac2181 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3968
diff changeset
   346
     That's almost the same as #removeAll, but keeps the contentsArray.
1095
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   347
     Returns the receiver."
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   348
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   349
     |prevSize|
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   350
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   351
     prevSize := self size.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   352
     super reset.
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   353
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   354
     prevSize ~~ 0 ifTrue:[
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   355
        dependents notNil ifTrue:[
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   356
            self changed:#removeFrom: with:(Array with:1 with:prevSize)
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   357
        ]
adf956ca6cda reimplement messages because of change notifications
ca
parents: 1090
diff changeset
   358
     ].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   359
! !
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   360
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   361
!List methodsFor:'converting'!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   362
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   363
asList
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   364
    ^ self
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   365
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   366
    "Created: 14.2.1997 / 16:25:55 / cg"
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   367
! !
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   368
810
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   369
!List methodsFor:'copying'!
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   370
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   371
skipInstvarIndexInDeepCopy:index
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   372
    "a helper for deepCopy; only indices for which this method returns
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   373
     false are copied in a deep copy."
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   374
2858
aeacd9c755ae class: List
Stefan Vogel <sv@exept.de>
parents: 2054
diff changeset
   375
    ^ index == 4    "/ skip dependents
810
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   376
! !
b27913d14137 deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents: 742
diff changeset
   377
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   378
!List methodsFor:'dependents access'!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   379
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   380
addDependent:anObject
1615
a37350aa843e oops - back to previous
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   381
    "make the argument, anObject be a dependent of the receiver."
1090
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   382
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   383
    ^ self addNonWeakDependent:anObject
1090
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   384
!
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   385
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
dependents 
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
    "return the dependents of the receiver"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
584
319da69edba2 dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
   389
    ^ dependents ? #()
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
584
319da69edba2 dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
   391
    "Created: / 14.2.1997 / 16:05:49 / cg"
319da69edba2 dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
   392
    "Modified: / 27.10.1997 / 19:37:33 / cg"
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
dependents:aCollection
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
    "set the dependents of the receiver"
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   398
    aCollection size == 0 ifTrue:[
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   399
        dependents := nil
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   400
    ] ifFalse:[
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   401
        dependents := aCollection.
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   402
    ].
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
611
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   404
    "Created: / 14.2.1997 / 16:05:58 / cg"
23ef909a3fdb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 610
diff changeset
   405
    "Modified: / 29.1.1998 / 10:54:52 / cg"
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   406
!
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   407
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   408
nonWeakDependents
612
cc2d6bd50cdc #nonWeakDependents always returns a collection.
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   409
    "return a Collection of dependents - empty if there is none.
606
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   410
     Since all dependencies are nonWeak in List, this is a dummy."
4419919ae433 shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents: 584
diff changeset
   411
1604
7f5c64c4fd90 dependencies fix
Claus Gittinger <cg@exept.de>
parents: 1567
diff changeset
   412
    ^ dependents ? #()
673
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   413
!
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   414
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   415
nonWeakDependents:newDeps
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   416
    "return a Collection of dependents - empty if there is none.
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   417
     Since all dependencies are nonWeak in List, this is a dummy."
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   418
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   419
    ^ self dependents:newDeps
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   420
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   421
    "Created: / 19.4.1996 / 10:29:43 / cg"
530ca09ba8d1 oops - non weak dependents.
tz
parents: 646
diff changeset
   422
    "Modified: / 30.1.1998 / 14:06:12 / cg"
1090
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   423
!
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   424
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   425
removeDependent:anObject
1090
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   426
    "make the argument, anObject be independent of the receiver.
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   427
     Since all dependencies are nonWeak in Model, this is simply
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   428
     forwarded to removeDependent:"
979886a925c8 nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   429
1638
4ca339939383 dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents: 1615
diff changeset
   430
    ^ self removeNonWeakDependent:anObject
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
! !
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   433
!List methodsFor:'filling & replacing'!
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   434
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   435
contents:aCollection
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   436
    "replace all elements in the receiver by aCollection,
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   437
     Redefined - can be done faster"
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   438
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   439
     |oldSize newSize|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   440
909
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   441
     aCollection isSequenceable ifFalse:[
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   442
        ^ super contents:aCollection
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   443
     ].
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   444
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   445
     oldSize := self size.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   446
     newSize := aCollection size.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   447
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   448
     newSize < oldSize ifTrue:[
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   449
        self replaceFrom:1 to:newSize with:aCollection startingAt:1.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   450
        self removeFromIndex:newSize+1 toIndex:oldSize.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   451
     ] ifFalse:[
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   452
        newSize > oldSize ifTrue:[
909
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   453
            oldSize == 0 ifTrue:[
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   454
                self addAll:aCollection       
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   455
            ] ifFalse:[
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   456
                self replaceFrom:1 to:oldSize with:aCollection startingAt:1.
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   457
                self addAll:aCollection from:oldSize+1 to:newSize beforeIndex:oldSize+1        
c4f759a283cf fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
   458
            ]
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   459
        ] ifFalse:[
1567
f4cc74d17aa7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1142
diff changeset
   460
            "/ same size
f4cc74d17aa7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1142
diff changeset
   461
            oldSize ~~ 0 ifTrue:[
f4cc74d17aa7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1142
diff changeset
   462
                self replaceFrom:1 to:newSize with:aCollection startingAt:1.
f4cc74d17aa7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1142
diff changeset
   463
            ]
908
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   464
        ]
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   465
     ].
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   466
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   467
     "
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   468
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   469
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   470
      l contents:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   471
      l        
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   472
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   473
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   474
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   475
      l addAll:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   476
      l contents:#(10 20 30).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   477
      l       
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   478
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   479
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   480
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   481
      l addAll:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   482
      l contents:#(10 20 30 40 50 60 70 80).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   483
      l      
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   484
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   485
      |l|
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   486
      l := List new.
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   487
      l addAll:#(1 2 3 4 5).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   488
      l contents:#(10 20 30 40 50).
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   489
      l      
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   490
     "
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   491
!
f628a3c801ca added #contents:
Claus Gittinger <cg@exept.de>
parents: 881
diff changeset
   492
1033
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   493
list:aCollection
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   494
    "replace all elements in the receiver by aCollection.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   495
     For compatibility with other smalltalks 
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   496
     (allows List to be sometimes used as a ListPresenter in ported Dolphin apps)"
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   497
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   498
    self contents:aCollection
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   499
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   500
    "
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   501
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   502
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   503
     l list:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   504
     l        
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   505
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   506
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   507
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   508
     l addAll:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   509
     l list:#(10 20 30).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   510
     l       
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   511
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   512
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   513
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   514
     l addAll:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   515
     l list:#(10 20 30 40 50 60 70 80).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   516
     l      
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   517
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   518
     |l|
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   519
     l := List new.
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   520
     l addAll:#(1 2 3 4 5).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   521
     l list:#(10 20 30 40 50).
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   522
     l      
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   523
    "
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   524
!
1eb9d3b3f91e added #list: (compatibility)
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
   525
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   526
replaceFrom:start to:stop with:aCollection startingAt:repStart
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   527
    "replace elements in the receiver between index start and stop,
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   528
     with elements  taken from replacementCollection starting at repStart.
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   529
     Redefined - can be done faster"
481
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   530
2999
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   531
    stop < start ifTrue:[^ self].
481
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   532
2999
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   533
    "/ see if there is really any change involved
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   534
    (self sameContentsFrom:start to:stop as:aCollection startingAt:repStart) ifTrue:[
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   535
        ^ self  "/ avoids useless change notifications
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   536
    ].
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   537
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   538
    super replaceFrom:start to:stop with:aCollection startingAt:repStart.
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   539
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   540
    dependents notNil ifTrue:[
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   541
        self changed:#replace: with:(Array with:start with:stop)
650cb6bee22d class: List
Claus Gittinger <cg@exept.de>
parents: 2991
diff changeset
   542
    ].
577
bb0af6ee9567 add basic functionality
ca
parents: 481
diff changeset
   543
646
613ef9177393 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 632
diff changeset
   544
    "Modified: / 20.5.1998 / 15:20:17 / cg"
2911
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   545
!
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   546
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   547
setContents:aCollection
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   548
    "replace the receiver's underlying collection by aCollection"
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   549
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   550
     aCollection isSequenceable ifFalse:[
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   551
        ^ super contents:aCollection
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   552
     ].
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   553
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   554
     contentsArray := aCollection.
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   555
     firstIndex := 1.
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   556
     lastIndex := aCollection size.
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   557
     self changed.
481
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   558
! !
cee9d23e4cfe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 480
diff changeset
   559
881
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   560
!List methodsFor:'testing'!
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   561
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   562
isList
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   563
    "return true, if the receiver is some kind of list collection;
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   564
     true is returned here - the method is redefined from Object."
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   565
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   566
    ^ true
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   567
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   568
    "Modified: / 11.2.2000 / 01:37:36 / cg"
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   569
! !
12d26b190305 added #isList query
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   570
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   571
!List class methodsFor:'documentation'!
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   572
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   573
version
3836
2b6978d20b39 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3301
diff changeset
   574
    ^ '$Header$'
480
a7759a27fc8a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   575
! !
2911
ca652035065b class: List
Claus Gittinger <cg@exept.de>
parents: 2858
diff changeset
   576