Skip to main content

%Collection.ListOfObj

class %Collection.ListOfObj extends %Collection.AbstractListOfObj, %Collection.Super

The %Collection.ListOfObj class represents a list of references to objects, each of which is associated with a numeric position in the list. The first element in the list is stored at position 1. The objects referred to must be registered. They can be either persistent objects or non-id objects.

Internally, a %Collection.ListOfObj object contains two lists: one for holding the OID values for the objects referred to (or their serialized state in the case of a list 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 list. For example, if list is an %Collection.ListOfObj object containing a list of Doctor objects (that is a list of OID values for Doctor objects stored in the database) then the following code fragment will automatically load the Doctor object at location 7 in the list 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=list.GetAt(7)
  Write doc.Name
  
Alternatively, we could use cascading dot syntax:
  Set name=list.GetAt(7).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 can not be used as 'stand alone' collections, for this use the %ListOfObjects.

Property Inventory

Method Inventory

Parameters

parameter IdCollection = 0;
If true then in the container we have an array of id's rather than an array of oid's

Properties

property Size as %Integer [ Calculated ];
Size is the number of elements contained in the list.
Property methods: SizeDisplayToLogical(), SizeIsValid(), SizeLogicalToDisplay(), SizeNormalize()

Methods

method %UnSwizzleAt(key As %Integer, force As %Integer = 0) as %Status
Unswizzles (removes from memory) the individual element at position key in the list.

Returns a %Status value indicating success or failure.

final method Count() as %Integer
Inherited description: Returns the number of elements contained in the list.
method DeSerialize(serialized As %String(MAXLEN="")) as %Status
Inherited description: Deserialize from string created with Serialize() back to collection
method Find(element As %ObjectIdentity, key As %Integer) as %String
Starting from, but not including, position key, Find finds the next element in the list whose OID value equals element. 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.

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.

method FindOref(oref As %RegisteredObject, key As %Integer = "", 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.

method GetAt(key As %Integer) as %RegisteredObject
Finds and returns the OREF value referring to the object at position key in the list.

GetAt returns the value of the element at location key or null string ("") if no element is found.

method GetNext(ByRef key As %Integer) as %RegisteredObject
Finds and returns the OREF value referring to the object at the position after key in the list. If key is a null string (""), it returns the OREF value of the first element in the list.

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

method GetObjectAt(key As %Integer, force As %Integer = 0) as %ObjectIdentity
Finds and returns the OID value referring to the object at position key in the list.

Returns the value of the element at location key or null string ("") if no element is found.

final method GetObjectIdAt(key As %Integer, force As %Integer = 0) as %String
Finds and returns the ID value referring to the object at position key in the list.

Returns the value of the element at location key or null string ("") if no element is found.

final method GetObjectIdNext(ByRef key As %Integer = "") as %String
Finds and returns the ID value referring to the object at the position after key in the list. If key is a null string (""), it returns the ID value of the first element in the list.

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

final method GetObjectIdPrevious(ByRef key As %Integer) as %String
Finds and returns the ID value referring to the object at the position before key in the list. If key is a null string (""), it returns the ID value of the last element in the list.

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

method GetObjectNext(ByRef key As %Integer) as %ObjectIdentity
Finds and returns the OID value referring to the object at the position after key in the list. If key is a null string (""), it returns the OID value of the first element in the list.

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

method GetObjectPrevious(ByRef key As %Integer) as %ObjectIdentity
Finds and returns the OID value referring to the object at the position before key in the list. If key is a null string (""), it returns the OID value of the last element in the list.

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

method GetPrevious(ByRef key As %Integer) as %RegisteredObject
Finds and returns the OREF value referring to the object at the position before key in the list. If key is a null string (""), it returns the OREF value of the last element in the list.

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

method Insert(oref As %RegisteredObject) as %Status
Inserts an element with OREF value oref at the end of the list.

Returns a %Status value indicating success or failure.

method InsertAt(oref As %RegisteredObject, key As %Integer) as %Status
Inserts an element with OREF value oref at position key.

To make room for the new element, the elements previously at or following position key are moved up by one position.

key must be in the following range:


1 <= index <= Count() + 1

Returns a %Status value indicating success or failure.
method InsertObject(oid As %ObjectIdentity) as %Status
Inserts an element with OID value oid at the end of the list.

Returns a %Status value indicating success or failure.

method InsertObjectAt(oid As %ObjectIdentity, key As %Integer) as %Status
Inserts an element with OID value oid at position key.

To make room for the new element, the elements previously at or following position key are moved up by one position.

key must be in the following range:


1 <= index <= Count() + 1

Returns a %Status value indicating success or failure.
method InsertObjectId(id As %String) as %Status
Inserts an element with ID value id at the end of the list.

Returns a %Status value indicating success or failure.

method InsertObjectIdAt(id As %String, key As %Integer) as %Status
Inserts an element with ID value id at position key.

To make room for the new element, the elements previously at or following position key are moved up by one position.

key must be in the following range:


1 <= index <= Count() + 1

Returns a %Status value indicating success or failure.
method IsDefined(key As %Integer) as %Boolean
Returns true (1) if a value is defined at location key, otherwise false (0).
Inherited description: Finds and returns the index value of the element at the location following key in the list. If key is a null string (""), then Next returns the position of the first element in the list (1).
Inherited description: Finds and returns the index value of the element at the location preceding key in the list. If key is a null string (""), then Previous returns the position of the last element in the list.
method RemoveAt(key As %Integer, Output success As %Boolean) as %ObjectIdentity
Removes the element at position key in the list. The elements following position key are moved to fill in the resulting gap.

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.

method Serialize(force As %Integer = 0) as %String
Serialize() constructs a serialized form of the collection as a string
method SetAt(oref As %RegisteredObject, key As %Integer) as %Status
Sets the OREF value of the element at position key to oref.

Returns a %Status value indicating success or failure.

method SetObjectAt(oid As %ObjectIdentity, key As %Integer) as %Status
Sets the OID value of the element at position key to oid.

Returns a %Status value indicating success or failure.

method SetObjectIdAt(id As %String, key As %Integer) as %Status
Sets the ID value of the element at position key to id.

Returns a %Status value indicating success or failure.

final method SizeGet() as %Integer
abstract method SizeSet(newvalue As %Integer) as %Status

Inherited Members

Inherited Properties

Inherited Methods

Subclasses

FeedbackOpens in a new tab