Squeak Class Documentation category index | class index  
 
Collection
  category: Collections-Abstract
  superclass: Object
  subclasses: CharacterSet Bag SequenceableCollection Set WeakRegistry EventMessageSet SkipList

I am the abstract superclass of all classes that represent a group of elements.

instance methods
  accessing
  anyOne
atRandom
capacity
size

  adapting
  adaptToCollection:andSend:
adaptToNumber:andSend:
adaptToPoint:andSend:
adaptToString:andSend:

  adding
  add:
add:withOccurrences:
addAll:
addIfNotPresent:

  arithmetic
  *
+
-
/
//
\\

  comparing
  hash

  converting
  asArray
asBag
asByteArray
asCharacterSet
asIdentitySet
asIdentitySkipList
asOrderedCollection
asSet
asSkipList
asSkipList:
asSortedArray
asSortedCollection
asSortedCollection:

  copying
  copyWith:
copyWithDependent:
copyWithout:
copyWithoutAll:

  enumerating
  allSatisfy:
anySatisfy:
associationsDo:
collect:
collect:thenSelect:
count:
detect:
detect:ifNone:
detectMax:
detectMin:
detectSum:
difference:
do:
do:separatedBy:
do:without:
groupBy:having:
inject:into:
intersection:
noneSatisfy:
reject:
select:
select:thenCollect:
union:

  filter streaming
  contents
flattenOnStream:
write:

  math functions
  abs
average
ceiling
floor
log
max
median
min
negated
range
reciprocal
rounded
sqrt
squared
sum
truncated

  printing
  printElementsOn:
printNameOn:
printOn:
storeOn:

  private
  emptyCheck
errorEmptyCollection
errorNoMatch
errorNotFound:
errorNotKeyed
toBraceStack:

  removing
  remove:
remove:ifAbsent:
removeAll:
removeAllFoundIn:
removeAllSuchThat:

  testing
  identityIncludes:
includes:
includesAllOf:
includesAnyOf:
includesSubstringAnywhere:
isCollection
isEmpty
isEmptyOrNil
isSequenceable
notEmpty
occurrencesOf:

class methods
  examples
  exampleFor:

  instance creation
  ofSize:
with:
with:with:
with:with:with:
with:with:with:with:
with:with:with:with:with:
with:with:with:with:with:with:
withAll:

  private
  initialize
randomForPicking

instance methods
  accessing top  
 

anyOne

Answer a representative sample of the receiver. This method can
be helpful when needing to preinfer the nature of the contents of
semi-homogeneous collections.


 

atRandom

Answer a random element of the receiver. Uses a shared random
number generator owned by class Collection. If you use this a lot,
define your own instance of Random and use #atRandom:. Causes
an error if self has no elements.


 

capacity

Answer the current capacity of the receiver.


 

size

Answer how many elements the receiver contains.


  adapting top  
 

adaptToCollection:andSend:

If I am involved in arithmetic with another Collection, return a Collection of
the results of each element combined with the scalar in that expression.


 

adaptToNumber:andSend:

If I am involved in arithmetic with a scalar, return a Collection of
the results of each element combined with the scalar in that expression.


 

adaptToPoint:andSend:

If I am involved in arithmetic with a scalar, return a Collection of
the results of each element combined with the scalar in that expression.


 

adaptToString:andSend:

If I am involved in arithmetic with a String, convert it to a Number.


  adding top  
 

add:

Include newObject as one of the receiver's elements. Answer newObject.
ArrayedCollections cannot respond to this message.


 

add:withOccurrences:

Add newObject anInteger times to the receiver. Answer newObject.


 

addAll:

Include all the elements of aCollection as the receiver's elements. Answer
aCollection. Actually, any object responding to #do: can be used as argument.


 

addIfNotPresent:

Include anObject as one of the receiver's elements, but only if there
is no such element already. Anwser anObject.


  arithmetic top  
 

*


 

+


 

-


 

/


 

//


 

\\


  comparing top  
 

hash

Answer an integer hash value for the receiver such that,
-- the hash value of an unchanged object is constant over time, and
-- two equal objects have equal hash values


  converting top  
 

asArray

Answer an Array whose elements are the elements of the receiver.
Implementation note: Cannot use ''Array withAll: self'' as that only
works for SequenceableCollections which support the replacement
primitive.


 

asBag

Answer a Bag whose elements are the elements of the receiver.


 

asByteArray

Answer a ByteArray whose elements are the elements of the receiver.
Implementation note: Cannot use ''ByteArray withAll: self'' as that only
works for SequenceableCollections which support the replacement
primitive.


 

asCharacterSet

Answer a CharacterSet whose elements are the unique elements of the receiver.
The reciever should only contain characters.


 

asIdentitySet


 

asIdentitySkipList

Answer a IdentitySkipList whose elements are the elements of the
receiver. The sort order is the default less than or equal.


 

asOrderedCollection

Answer an OrderedCollection whose elements are the elements of the
receiver. The order in which elements are added depends on the order
in which the receiver enumerates its elements. In the case of unordered
collections, the ordering is not necessarily the same for multiple
requests for the conversion.


 

asSet

Answer a Set whose elements are the unique elements of the receiver.


 

asSkipList

Answer a SkipList whose elements are the elements of the
receiver. The sort order is the default less than or equal.


 

asSkipList:

Answer a SkipList whose elements are the elements of the
receiver. The sort order is defined by the argument, aSortBlock.


 

asSortedArray

Return a copy of the receiver in sorted order, as an Array. 6/10/96 sw


 

asSortedCollection

Answer a SortedCollection whose elements are the elements of the
receiver. The sort order is the default less than or equal.


 

asSortedCollection:

Answer a SortedCollection whose elements are the elements of the
receiver. The sort order is defined by the argument, aSortBlock.


  copying top  
 

copyWith:

Answer a new collection with newElement added (as last
element if sequenceable).


 

copyWithDependent:

Answer a new collection with newElement added (as last
element if sequenceable).


 

copyWithout:

Answer a copy of the receiver that does not contain any
elements equal to oldElement.


 

copyWithoutAll:

Answer a copy of the receiver that does not contain any elements
equal to those in aCollection.


  enumerating top  
 

allSatisfy:

Evaluate aBlock with the elements of the receiver.
If aBlock returns false for any element return false.
Otherwise return true.


 

anySatisfy:

Evaluate aBlock with the elements of the receiver.
If aBlock returns true for any element return true.
Otherwise return false.


 

associationsDo:

Evaluate aBlock for each of the receiver's elements (key/value
associations). If any non-association is within, the error is not caught now,
but later, when a key or value message is sent to it.


 

collect:

Evaluate aBlock with each of the receiver's elements as the argument.
Collect the resulting values into a collection like the receiver. Answer
the new collection.


 

collect:thenSelect:

Utility method to improve readability.


 

count:

Evaluate aBlock with each of the receiver's elements as the argument.
Answer the number of elements that answered true.


 

detect:

Evaluate aBlock with each of the receiver's elements as the argument.
Answer the first element for which aBlock evaluates to true.


 

detect:ifNone:

Evaluate aBlock with each of the receiver's elements as the argument.
Answer the first element for which aBlock evaluates to true. If none
evaluate to true, then evaluate the argument, exceptionBlock.


 

detectMax:

Evaluate aBlock with each of the receiver's elements as the argument.
Answer the element for which aBlock evaluates to the highest magnitude.
If collection empty, return nil. This method might also be called elect:.


 

detectMin:

Evaluate aBlock with each of the receiver's elements as the argument.
Answer the element for which aBlock evaluates to the lowest number.
If collection empty, return nil.


 

detectSum:

Evaluate aBlock with each of the receiver's elements as the argument.
Return the sum of the answers.


 

difference:

Answer the set theoretic difference of two collections.


 

do:

Evaluate aBlock with each of the receiver's elements as the argument.


 

do:separatedBy:

Evaluate the elementBlock for all elements in the receiver,
and evaluate the separatorBlock between.


 

do:without:

Enumerate all elements in the receiver.
Execute aBlock for those elements that are not equal to the given item


 

groupBy:having:

Like in SQL operation - Split the recievers contents into collections of
elements for which keyBlock returns the same results, and return those
collections allowed by selectBlock. keyBlock should return an Integer.


 

inject:into:

Accumulate a running value associated with evaluating the argument,
binaryBlock, with the current value of the argument, thisValue, and the
receiver as block arguments. For instance, to sum the numeric elements
of a collection, aCollection inject: 0 into: [:subTotal :next | subTotal +
next].


 

intersection:

Answer the set theoretic intersection of two collections.


 

noneSatisfy:

Evaluate aBlock with the elements of the receiver.
If aBlock returns false for all elements return true.
Otherwise return false


 

reject:

Evaluate aBlock with each of the receiver's elements as the argument.
Collect into a new collection like the receiver only those elements for
which aBlock evaluates to false. Answer the new collection.


 

select:

Evaluate aBlock with each of the receiver's elements as the argument.
Collect into a new collection like the receiver, only those elements for
which aBlock evaluates to true. Answer the new collection.


 

select:thenCollect:

Utility method to improve readability.


 

union:

Answer the set theoretic union of two collections.


  filter streaming top  
 

contents


 

flattenOnStream:


 

write:


  math functions top  
 

abs

Absolute value of all elements in the collection


 

average


 

ceiling


 

floor


 

log


 

max


 

median


 

min


 

negated

Negated value of all elements in the collection


 

range


 

reciprocal

Return the reciever full of reciprocated elements


 

rounded


 

sqrt


 

squared


 

sum

This is implemented using a variant of the normal inject:into: pattern.
The reason for this is that it is not known whether we're in the normal
number line, i.e. whether 0 is a good initial value for the sum.
Consider a collection of measurement objects, 0 would be the unitless
value and would not be appropriate to add with the unit-ed objects.


 

truncated


  printing top  
 

printElementsOn:


 

printNameOn:


 

printOn:

Append a sequence of characters that identify the receiver to aStream.


 

storeOn:

Refer to the comment in Object|storeOn:.


  private top  
 

emptyCheck


 

errorEmptyCollection


 

errorNoMatch


 

errorNotFound:

Actually, this should raise a special Exception not just an error.


 

errorNotKeyed


 

toBraceStack:

Push receiver's elements onto the stack of thisContext sender. Error if receiver does
not have itsSize elements or if receiver is unordered.
Do not call directly: this is called by {a. b} _ ... constructs.


  removing top  
 

remove:

Remove oldObject from the receiver's elements. Answer oldObject
unless no element is equal to oldObject, in which case, raise an error.
ArrayedCollections cannot respond to this message.


 

remove:ifAbsent:

Remove oldObject from the receiver's elements. If several of the
elements are equal to oldObject, only one is removed. If no element is
equal to oldObject, answer the result of evaluating anExceptionBlock.
Otherwise, answer the argument, oldObject. ArrayedCollections cannot
respond to this message.


 

removeAll:

Remove each element of aCollection from the receiver. If successful for
each, answer aCollection. Otherwise create an error notification.
ArrayedCollections cannot respond to this message.


 

removeAllFoundIn:

Remove each element of aCollection which is present in the receiver
from the receiver. Answer aCollection. No error is raised if an element
isn't found. ArrayedCollections cannot respond to this message.


 

removeAllSuchThat:

Evaluate aBlock for each element and remove all that elements from
the receiver for that aBlock evaluates to true. Use a copy to enumerate
collections whose order changes when an element is removed (i.e. Sets).


  testing top  
 

identityIncludes:

Answer whether anObject is one of the receiver's elements.


 

includes:

Answer whether anObject is one of the receiver's elements.


 

includesAllOf:

Answer whether all the elements of aCollection are in the receiver.


 

includesAnyOf:

Answer whether any element of aCollection is one of the receiver's elements.


 

includesSubstringAnywhere:

Answer whether the receiver includes, anywhere in its nested structure, a string that has testString as a substring


 

isCollection

Return true if the receiver is some sort of Collection and responds to basic collection messages such as #size and #do:


 

isEmpty

Answer whether the receiver contains any elements.


 

isEmptyOrNil

Answer whether the receiver contains any elements, or is nil. Useful in numerous situations where one wishes the same reaction to an empty collection or to nil


 

isSequenceable


 

notEmpty

Answer whether the receiver contains any elements.


 

occurrencesOf:

Answer how many of the receiver's elements are equal to anObject.


class methods
  examples top  
 

exampleFor:

Provide a MethodCall with a valid example of aSelector, ready to run. If 'all', provide all tests we know about for SUnit tests. When 'all', each will be a Verifier, with an expected answer. Returns a list of MethodCalls, Verifiers, or VerifierOfPropertys.


  instance creation top  
 

ofSize:

Create a new collection of size n with nil as its elements.
This method exists because OrderedCollection new: n creates an
empty collection, not one of size n.


 

with:

Answer an instance of me containing anObject.


 

with:with:

Answer an instance of me containing the two arguments as elements.


 

with:with:with:

Answer an instance of me containing the three arguments as elements.


 

with:with:with:with:

Answer an instance of me, containing the four arguments as the elements.


 

with:with:with:with:with:

Answer an instance of me, containing the five arguments as the elements.


 

with:with:with:with:with:with:

Answer an instance of me, containing the six arguments as the elements.


 

withAll:

Create a new collection containing all the elements from aCollection.


  private top  
 

initialize

Set up a Random number generator to be used by atRandom when the
user does not feel like creating his own Random generator.


 

randomForPicking