Skip to main content

%Collection.ArrayOfObj

Class %Collection.ArrayOfObj Extends (%Collection.AbstractArrayOfObj, Super) [ Inheritance = right, System = 2 ]

For information on this class, see Working with Collections.

The %Collection.ArrayOfObjects class represents an array of references to objects, each of which is associated with a unique key value. Keys can have any value, string or numeric. The objects referred to must be registered. They can be either persistent objects or non-id objects.

Internally, an %Collection.ArrayOfObjects object contains two arrays: one for holding the OID values for the objects referred to (or their serialized state in the case of an array of non-id objects); and another for holding the OREF values for any objects that have been explicitly referred to, and hence "swizzled" into memory. Swizzling (loading an object into memory and generating an OREF value for it) happens automatically whenever the user refers to an object within the array.

For example, if array is an %Collection.ArrayOfObjects object containing an array of Doctor objects (that is an array of OID values for Doctor objects stored in the database) then the following code fragment will automatically load the Doctor object associated with the key "Primary" into memory and generate an OREF value referring to the in-memory version of the Doctor object. This OREF value can then be used to access the properties and methods of the Doctor object: Set doc=array.GetAt("Primary") Write doc.Name

Alternatively, we could use cascading dot syntax: Set name=array.GetAt("Primary").Name These %Collection classes can only be used when you have a collection property of another object as they rely on storing the data inside the parent object, they cannot be used as 'standalone' collections, for this use the %ArrayOfObjects.

Parameters

IdCollection

Parameter IdCollection As BOOLEAN = 0;

If true then in the container we have an array of id's rather than an array of oid's

Methods

Count

Method Count() As %Integer

Returns the number of elements contained in the array.

Find

Method Find(element As %ObjectIdentity, key As %String) As %String

Starting from, but not including, location key, finds the next element in the array whose OID value equals element.

If key is a null string (""), the search starts at the beginning of the array.

Find returns the key associated with the found element or null string ("") if no element is found.

FindObjectId

Method FindObjectId(id As %String, key As %Integer) As %String

Starting from, but not including, position key, FindObjectId finds the next element in the list whose ObjectId equals id. If key is a null string, Find starts at the beginning of the list.

Find returns the position of the found element or null string ("") if no element was found.

FindOref

Method FindOref(oref As %RegisteredObject, key As %String = "", id As %String = "") As %String

Starting from, but not including, location key, finds the next element in the array whose Oref value equals oref.

If key is a null string (""), the search starts at the beginning of the array.

FindOref returns the key associated with the found element or null string ("") if no element is found. Unswizzled references are compared to oref.%Oid() and if equal, swizzling will occur.

GetAt

Method GetAt(key As %String) As %RegisteredObject

Finds and returns the OREF value of the element associated with key.

GetAt returns the OREF value of the element associated with key or null string ("") if no element is found.

GetObjectAt

Method GetObjectAt(key As %String, force As %Integer = 0) As %ObjectIdentity

Finds and returns the OID value of the element associated with key.

GetObjectAt returns the OID value of the element associated with key or null string ("") if no element is found.

GetObjectIdAt

Method GetObjectIdAt(key As %String, force As %Integer = 0) As %String [ CodeMode = expression ]

Finds and returns the ID value of the element associated with key.

GetObjectIdAt returns the ID value of the element associated with key or null string ("") if no element is found.

GetNext

Method GetNext(ByRef key As %String) As %RegisteredObject

Finds and returns the OREF value of the element at the location after key in the array. If key is a null string (""), it returns the OREF value of the first element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the end of the array.

GetObjectNext

Method GetObjectNext(ByRef key As %String) As %ObjectIdentity

Finds and returns the OID value of the element at the location after key in the array. If key is a null string (""), it returns the OID value of the first element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the end of the array.

GetObjectIdNext

Method GetObjectIdNext(ByRef key As %String) As %String [ CodeMode = expression ]

Finds and returns the ID value of the element at the location after key in the array. If key is a null string (""), it returns the ID value of the first element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the end of the array.

GetPrevious

Method GetPrevious(ByRef key As %String) As %RegisteredObject

Finds and returns the OREF value of the element at the location before key in the array. If key is a null string (""), it returns the OREF value of the last element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the beginning of the array.

GetObjectPrevious

Method GetObjectPrevious(ByRef key As %String) As %ObjectIdentity

Finds and returns the OID value of the element at the location before key in the array. If key is a null string (""), it returns the OID value of the last element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the beginning of the array.

GetObjectIdPrevious

Method GetObjectIdPrevious(ByRef key As %String) As %String [ CodeMode = expression ]

Finds and returns the ID value of the element at the location before key in the array. If key is a null string (""), it returns the ID value of the last element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the beginning of the array.

RemoveAt

Method RemoveAt(key As %String, Output success As %Boolean) As %ObjectIdentity

Removes the element associated with key in the array.

RemoveAt returns the OID value of the removed element or null string ("") if no element was removed. It also has a success output argument that returns true if the item was removed and false if it was not.

SetAt

Method SetAt(oref As %RegisteredObject, key As %String) As %Status

Sets the OREF value of the element associated with key to element.

Returns a %Status value indicating success or failure.

SetObjectAt

Method SetObjectAt(oid As %ObjectIdentity, key As %String) As %Status

Sets the OID value of the element associated with key to element.

Returns a %Status value indicating success or failure.

SetObjectIdAt

Method SetObjectIdAt(id As %String, key As %String) As %Status [ CodeMode = expression ]

Sets the ID value of the element associated with key to element.

Returns a %Status value indicating success or failure.

%UnSwizzleAt

Method %UnSwizzleAt(key As %String, force As %Integer = 0) As %Status

Unswizzles (removes from memory) the element associated with key in the array.

Returns a %Status value indicating success or failure.

%OnConstructClone

Method %OnConstructClone(oref As %RegisteredObject, deep As %Boolean = 0, ByRef cloned As %String) As %Status [ Private ]

IsDefined

Method IsDefined(key As %String) As %Boolean [ CodeMode = expression, Final ]

Define

Method Define(key As %String) As %Boolean [ CodeMode = expression, Final ]

Next

Method Next(key As %String = "") As %String [ CodeMode = expression, Final ]

Previous

Method Previous(key As %String = "") As %String [ CodeMode = expression, Final ]

Serialize

Method Serialize(force As %Integer = 0) As %String(MAXLEN="")

Serialize() constructs a serialized form of the collection as a string

DeSerialize

Method DeSerialize(serialized As %String(MAXLEN="")) As %Status