Object Rexx Collection Classes
Classification Tree
Classification Tree (ooRexx 3.1)
Classification Tree
PUT or the synonym "[ ]=" collects (stores) an object with an index
AT or the synonym "[ ]" retrieves an object from a collection by its index
Classification Tree
Collection classes allow the use of the class method OF supplying a list of objects for the collection instead of the class method NEW.
Iterating over the collection using a DO...OVER block statement
Iterating over the collection using a SUPPLIER object (see below)
Classification Tree
Classification Tree
Array objects allow the storing of objects with a pre-defined numeric index, which must be a whole number starting with the value 1
Output:
an Array:
[a]
[b]
[b]
[c]Classification Tree
Output:
an Array:
[b]
[c]
[a]
[b]
Classification Tree
List objects allow the storing of objects (instances, values) in the form of a list, i.e. in an ordered manner
Output:
a List:
[a]
[b]
[b]
[c]Classification Tree
Queue objects allow the storing of objects (instances, values) at the "head" (PUSH) or at the "tail" (QUEUE), i.e. in an ordered manner
Output:
a Queue:
[c]
[b]
[a]
[b]
Classification Tree
Max
und
Moritz
haben
...Output:
a Stream:
[Max]
[und]
[Moritz]
[haben]
[...]
Classification Tree
Max
und
Moritz
haben
...5 Items
Output:
a Stream becomes an Array,
the array has 5 items (lines):
[Max]
[und]
[Moritz]
[haben]
[...]
Classification Tree
Classification Tree
Directory objects allow the collecting of objects with a user defined index of type string
tmpColl = .directory ~new
tmpColl["a_index"] = "a"
tmpColl ~"[]="("b", "b_index")
tmpColl ~~PUT("b", "b_index" ) ~~PUT("c", "c_index")
tmpColl ~wu= "WU Wien"
tmpColl ~rgf="Rony G. Flatscher"
SAY "Acronym 'WU':" tmpColl~wu || ", 'RGF':" tmpColl~rgf
SAY tmpColl~string":"
DO i OVER tmpColl
SAY "["i"]"
END
Output:
Acronym 'WU': WU Wien, 'RGF': Rony G. Flatscher
a Directory:
[RGF]
[c_index]
[b_index]
[a_index]
[WU]
order could be different
Classification Tree
Relation objects allow the collecting of objects with a user defined index of any type (multiple objects per index possible)
Output:
a Relation:
[c_index]
[b_index]
[b_index]
[a_index]
order could be different
Classification Tree
Bag objects allow the collecting of objects with a user defined index of any type (multiple objects per index possible, index and object are the same, hence index can be left out)
Output:
a Bag:
[a]
[b]
[b]
[c]
order could be different
Classification Tree
Table objects allow the collecting of objects with a user defined index of any type (one object per index)
Output:
a Table:
[c_index]
[b_index]
[a_index]
order could be different
Classification Tree
Set objects allow the collecting of objects with a user defined index of any type (one object per index, index and object are the same, hence index can be left out)
Output:
a Set:
[a]
[b]
[c]
order could be different
Classification Tree
Stem objects allow the collecting of objects with a user defined index of type string (one object per index)
Output:
a Stem:
[a_index]
[c_index]
[b_index]
order could be different
Classification Tree
The MAKEARRAY method allows to transform any collection object into an Array object such that array methods can be employed (e.g. ITEMS, PUT, REMOVE, SORT, ...).
Output:
a Array:
[a_index]
[c_index]
[b_index]
Classification Tree
tmpColl = .list~of("orange", "banana", "apple")
tmpArray = tmpColl~makeArray -- turn collection into array
say "there are" tmpArray~items "items in the array (list)"
SAY "an" tmpArray~class~id":"
DO i OVER tmpArray
SAY "["i"]"
END
say "... and in sorted order:"
DO i OVER tmpArray~sort -- sort array
SAY "["i"]"
END
Output:
there are 3 items in the array (list)
an Array:
[orange]
[banana]
[apple]
... and in sorted order:
[apple]
[banana]
[orange]
Classification Tree
"replace" causes the file's old content to be deletedapple
banana
orangeClassification Tree (ooRexx 3.1)
Classification Tree
Supplier objects allow enumerating all objects contained in a collection
All builtin collection classes possess a method SUPPLIER which returns a snapshot of the collection and returns it in the form of a SUPPLIER object
"Blueprint" code for enumerating all collected objects of a collection using the methods of its SUPPLIER object
Classification Tree
ooRexx 5 introduces the ability to loop over a collection object directly
("DO WITH … OVER ...") assigning the index value and the item value to the defined loop variables in each iteration
"Blueprint" code for enumerating all collected objects (using implicitly the collection's SUPPLIER object)
Classification Tree
Output:
a Relation:
index [c_index] item [c]
index [b_index] item [b]
index [b_index] item [b]
index [a_index] item [a]
order could be different
Classification Tree
Output:
an Array:
index [1,1] item [b]
index [1,2] item [c]
index [2,3] item [a]
index [4,5] item [b]
order will be always the same!
Classification Tree
Output:
a Set:
index [a] item [a]
index [b] item [b]
index [c] item [c]
order could be different
Classification Tree
Classification Tree (ooRexx 3.1)
Classification Tree
Two Bag collections
coll_1 = .bag ~of("a", "b", "b")
coll_2 = .bag ~of( "b", "b", "c")
CALL dump coll_1~UNION(coll_2), "UNION "
CALL dump coll_1~INTERSECTION(coll_2), "INTERSECTION"
CALL dump coll_1~XOR(coll_2), "XOR "
CALL dump coll_1~DIFFERENCE(coll_2), "DIFFERENCE "
SAY coll_1~SUBSET(coll_1) "-" coll_1~SUBSET(coll_2)
::ROUTINE dump
USE ARG tmpColl, title
.output~CHAROUT( title tmpColl~string": ")
DO i OVER tmpColl
.output~CHAROUT("["i"] ")
END
.output~say
Output:
UNION a Bag: [a] [b] [b] [b] [b] [c]
INTERSECTION a Bag: [b] [b]
XOR a Bag: [a] [c]
DIFFERENCE a Bag: [a]
1 - 0
order could be different
Classification Tree
A Set and a Bag collection
coll_1 = .set ~of("a", "b", "b")
coll_2 = .bag ~of( "b", "b", "c")
CALL dump coll_1~UNION(coll_2), "UNION "
CALL dump coll_1~INTERSECTION(coll_2), "INTERSECTION"
CALL dump coll_1~XOR(coll_2), "XOR "
CALL dump coll_1~DIFFERENCE(coll_2), "DIFFERENCE "
SAY coll_1~SUBSET(coll_1) "-" coll_1~SUBSET(coll_2)
::ROUTINE dump
USE ARG tmpColl, title
.output~CHAROUT( title tmpColl~string": ")
DO i OVER tmpColl
.output~CHAROUT("["i"] ")
END
.output~say
Output:
UNION a Set: [a] [b] [c]
INTERSECTION a Set: [b]
XOR a Set: [a] [c]
DIFFERENCE a Set: [a]
1 - 0
order could be different
Classification Tree
A Bag and a Set collection
coll_1 = .bag ~of("a", "b", "b")
coll_2 = .set ~of( "b", "b", "c")
CALL dump coll_1~UNION(coll_2), "UNION "
CALL dump coll_1~INTERSECTION(coll_2), "INTERSECTION"
CALL dump coll_1~XOR(coll_2), "XOR "
CALL dump coll_1~DIFFERENCE(coll_2), "DIFFERENCE "
SAY coll_1~SUBSET(coll_1) "-" coll_1~SUBSET(coll_2)
::ROUTINE dump
USE ARG tmpColl, title
.output~CHAROUT( title tmpColl~string": ")
DO i OVER tmpColl
.output~CHAROUT("["i"] ")
END
.output~say
Output:
UNION a Bag: [a] [b] [b] [b] [c]
INTERSECTION a Bag: [b]
XOR a Bag: [a] [b] [c]
DIFFERENCE a Bag: [a] [b]
1 - 0
order could be different
Classification Tree
WU
Prof. Mag. Dr. Rony G. Flatscher
Welthandelsplatz 1
1020 Wien/Vienna
Austria/Europe
www: www.wu.ac.at