milestonexprotectrestpython.xprcollection

Module: xprcollection.py

Revision History

Date Version Description
2023/07/11 1.0.0.0 Initial Version.

@export
class XPRCollection(typing.Iterable):

Collection of objects.

Threadsafety:

This class is fully thread-safe.

XPRCollection(itemType: type = None)

Initializes a new instance of the class.

Arguments:
  • itemType (type): Type of items this collection will contain.
def append(self, item) -> None:

Adds a new item to the collection.

Arguments:
  • item (object): Item that will be added to the collection.
Raises:
  • TypeError: Item argument is not of a type specified when the collection was initialized.
count: int

Returns the number of items in the collection.

Returns:

The number of items in the collection.

def clear(self) -> None:

Removes all items in the collection.

def extend(self, other: object) -> None:

Extends the collection with items from another collection.

Arguments:
  • other (object): Collection of items to add to the collection.
def get(self, index: int) -> object:

Read an item from the collection at the specified index.

Arguments:
  • index (int): Index of the collection item to get.
Returns:

The collection item at the specified index.

def insert(self, index: int, item: object) -> None:

Inserts a new item in the collection at the specified index.

Arguments:
  • index (int): Index at which to insert the new item.
  • item (object): Item that will be added to the collection.
Raises:
  • TypeError: Item argument is not of a type specified when the collection was initialized.
length: int

Returns the number of items in the collection.

Returns:

The number of items in the collection.

def pop(self) -> object:

Remove and return the last item from the collection.

Returns:

The last item from the collection.

def remove(self, item: object) -> None:

Removes an item from the collection.

Arguments:
  • item (object): Item that will be removed from the collection.
Raises:
  • TypeError: Item argument is not of a type specified when the collection was initialized.
def sort(self, **kwargs) -> None:

Sorts the collection items by Name (default).

Use the following guidelines when calling a sort method that uses key=lambda syntax:

# good syntax, as it handles x.Name = None values.
epColl.sort(key=lambda x: x.Name or "", reverse=False)

# bad syntax, as the sort will fail if x.Name = None!
epColl.sort(key=lambda x: x.Name, reverse=False)