Reference Source
public class | source

CollectionBase

Extends:

LoggableErrorable → CollectionBase

Direct Subclass:

Collection, CollectionVersion

Base class for all collections classes.

Example:

API:
		->set_all(arg_items):nothing - Set all collection items.
		->get_all(arg_types):array - Get all collection items or filter items with given type.
		->get_all_names(arg_types):array - Get all items names with or without a filter on items types.
		->get_all_ids():array - Get all items ids with or without a filter on items types.

		->item(arg_name):Instance - Get an item by its name.

		->get_count():number - Get all items count.
		->get_first():object|undefined - Get first item.
		->get_last():object|undefined - Get last item.

		->add(arg_item):nothing - Add an item to the collection.
		->add_first(arg_item):nothing - Add an item to the collection at the first position.
		->remove(arg_item):nothing - Remove an item from the collection.
		->has(arg_item):boolean -  Test if an item is inside the collection.

		->find_by_name(arg_name):Instance|undefined - Find an item by its name into the collection.
		->find_by_id(arg_id):Instance|undefined - Find an item by its id into the collection.
		->find_by_attr(arg_attr_name, arg_attr_value):Instance|undefined - Find an item by one of its attributes into the collection.
		->find_by_filter(arg_filter_function):Instance|undefined - Find an item by a filter function.

		->filter_by_attr(arg_attr_name, arg_attr_value):array - Filter items by one of theirs attributes into the collection.
		->filter_by_filter(arg_filter_function):array - Filter items by a filter function.

		->get_accepted_types():array - Get all collection accepted types.
		->set_accepted_types(arg_types):nothing - Set all collection accepted types.
		->add_accepted_type(arg_type):nothing - Add one collection accepted type.
		->has_accepted_type(arg_type):boolean - Test if collection has given accepted type.

		->forEach(arg_cb):nothing - forEach wrapper on ordered items.

Constructor Summary

Public Constructor
public

constructor(): nothing

Create a collection of Instance objects.

Member Summary

Public Members
public

Class type flag.

Private Members
private

Accepted types array.

private

_items_array: array

Items array.

private

Items ids map.

private

Items names map.

Method Summary

Public Methods
public

add(arg_item: Instance): nothing

Add an item to the collection.

public

add_accepted_type(arg_type: string): nothing

Add one collection accepted type.

public

add_first(arg_item: Instance): nothing

Add an item to the collection at the first position.

public

filter_by_attr(arg_attr_name: string, arg_attr_value: any): array

Filter items by one of theirs attributes into the collection.

public

filter_by_filter(arg_filter_function: string): array

Filter items by a filter function.

public

find_by_attr(arg_attr_name: string, arg_attr_value: any): Instance | undefined

Find an item by one of its attributes into the collection.

public

find_by_filter(arg_filter_function: string): Instance | undefined

Find an item by a filter function.

public

Find an item by its id into the collection.

public

Find an item by its name into the collection.

public

forEach(arg_cb: function): nothing

forEach wrapper on ordered items.

public

get(arg_name: string): Instance | undefined

Get an item by its name.

public

Get all collection accepted types.

public

get_all(arg_types: array | string | nothing): array

Get all collection items or filter items with given type.

public

get_all_ids(): array

Get all items ids with or without a filter on items types.

public

get_all_names(arg_types: array | string | nothing): array

Get all items names with or without a filter on items types.

public

Get all items count.

public

Get first item.

public

Get last item.

public

has(arg_item: Instance): boolean

Test if an item is inside the collection.

public

Test if collection has given accepted type.

public

item(arg_name: string): Instance | undefined

Get an item by its name.

public

remove(arg_item: Instance): nothing

Remove an item from the collection.

public

set_accepted_types(arg_types: array): nothing

Set all collection accepted types.

public

set_all(arg_items: Instance | array): nothing

Set all collection items.

public

toString(): *

Format string dump.

Private Methods
private

_add(arg_item: Instance): nothing

Add an item to the collection without type checks (unsafe).

private

_add_first(arg_item: Instance): nothing

Add an item to the collection without type checks at first position (unsafe).

private

_get_all(): array

Get all collection items.

private

_has(arg_item: Instance): boolean

Test if an item is inside the collection without type checks (unsafe).

private

_remove(arg_item: Instance): nothing

Remove an item from the collection without type checks (unsafe).

private

_set_all(arg_items: array): nothing

Set all collection items.

Inherited Summary

From class Loggable
public

Log context.

public

Class type flag.

public

Trace is enabled for this flag.

private

Logger manager instance (default undefined)

public

debug(args: string | array): nothing

Trace DEBUG formatted message.

public

disable_trace(): nothing

Disable traces.

public

enable_trace(): nothing

Enable traces.

public

enter_group(arg_group: string): nothing

Trace INFO message on "enter trace group".

public

error(args: string | array): nothing

Trace ERROR formatted message.

public

Define get class name method for non Instance classes.

public

Get instance context.

public

Get logger manager.

public

Define get instance name method for non Instance classes.

public

Get trace flag.

public

info(args: string | array): nothing

Trace INFO formatted message.

public

leave_group(arg_group: string): nothing

Trace INFO message on "leave trace group".

public

separate_level_1(): nothing

Trace INFO trace level 1 separator.

public

separate_level_2(): nothing

Trace INFO trace level 2 separator.

public

separate_level_3(): nothing

Trace INFO trace level 3 separator.

public

set_trace(arg_value: boolean): nothing

Set trace flag.

public

should_trace(arg_traces_cfg: object): boolean

Calculate should trace flag.

public

should_trace_class(arg_traces_cfg: object): boolean

Calculate should trace flag for classes.

public

should_trace_collection_item(arg_traces_cfg: object, arg_collection_name: string, arg_this_item_accessor: string): boolean

Calculate should trace flag for given collection of names or patterns.

public

should_trace_module(arg_traces_cfg: object): boolean

Calculate should trace flag for modules.

public

should_trace_name(arg_traces_cfg: object): boolean

Calculate should trace flag for instances names.

public

Toggle trace flag.

public

Update trace enabled flag.

public

warn(args: string | array): nothing

Trace WARN formatted message.

From class Errorable
private

Error text (default null).

private

Has error flag (default false).

public

error(arg_msg: string): nothing

Set an error.

public

Default helper for "not implemented" error.

public

Get error message.

public

Test is an error is set.

Public Constructors

public constructor(): nothing source

Create a collection of Instance objects.

Override:

Errorable#constructor

Return:

nothing

Public Members

public is_collection_base: boolean source

Class type flag.

Private Members

private _accepted_types: array source

Accepted types array.

private _items_array: array source

Items array.

private _items_by_id: object source

Items ids map.

private _items_by_name: object source

Items names map.

Public Methods

public add(arg_item: Instance): nothing source

Add an item to the collection.

Params:

NameTypeAttributeDescription
arg_item Instance

Instance item.

Return:

nothing

public add_accepted_type(arg_type: string): nothing source

Add one collection accepted type.

Params:

NameTypeAttributeDescription
arg_type string

accepted types string.

Return:

nothing

public add_first(arg_item: Instance): nothing source

Add an item to the collection at the first position.

Params:

NameTypeAttributeDescription
arg_item Instance

Instance item.

Return:

nothing

public filter_by_attr(arg_attr_name: string, arg_attr_value: any): array source

Filter items by one of theirs attributes into the collection.

Params:

NameTypeAttributeDescription
arg_attr_name string

instance attribute name.

arg_attr_value any

instance attribute value.

Return:

array

public filter_by_filter(arg_filter_function: string): array source

Filter items by a filter function.

Params:

NameTypeAttributeDescription
arg_filter_function string

function to apply on instance, returns a boolean.

Return:

array

public find_by_attr(arg_attr_name: string, arg_attr_value: any): Instance | undefined source

Find an item by one of its attributes into the collection.

Params:

NameTypeAttributeDescription
arg_attr_name string

instance attribute name.

arg_attr_value any

instance attribute value.

Return:

Instance | undefined

public find_by_filter(arg_filter_function: string): Instance | undefined source

Find an item by a filter function.

Params:

NameTypeAttributeDescription
arg_filter_function string

function to apply on instance, returns a boolean.

Return:

Instance | undefined

public find_by_id(arg_id: string): Instance | undefined source

Find an item by its id into the collection.

Params:

NameTypeAttributeDescription
arg_id string

instance id.

Return:

Instance | undefined

public find_by_name(arg_name: string): Instance | undefined source

Find an item by its name into the collection.

TODO: optimize with a map index.

Params:

NameTypeAttributeDescription
arg_name string

instance name.

Return:

Instance | undefined

public forEach(arg_cb: function): nothing source

forEach wrapper on ordered items.

Params:

NameTypeAttributeDescription
arg_cb function

callback to call on each item.

Return:

nothing

public get(arg_name: string): Instance | undefined source

Get an item by its name.

Params:

NameTypeAttributeDescription
arg_name string

instance name.

Return:

Instance | undefined

public get_accepted_types(): array source

Get all collection accepted types.

Return:

array

array of types strings.

public get_all(arg_types: array | string | nothing): array source

Get all collection items or filter items with given type.

Params:

NameTypeAttributeDescription
arg_types array | string | nothing

type or types for items filtering.

Return:

array

all or filtered items, empty array if not found.

public get_all_ids(): array source

Get all items ids with or without a filter on items types.

Return:

array

all items ids.

public get_all_names(arg_types: array | string | nothing): array source

Get all items names with or without a filter on items types.

Params:

NameTypeAttributeDescription
arg_types array | string | nothing

type or types for items filtering.

Return:

array

all or filtered items names, empty array if not found.

public get_count(): number source

Get all items count.

Return:

number

all items count.

public get_first(): object | undefined source

Get first item.

Return:

object | undefined

first collection items or undefined if collection is empty.

public get_last(): object | undefined source

Get last item.

Return:

object | undefined

last collection items or null if collection is empty.

public has(arg_item: Instance): boolean source

Test if an item is inside the collection.

Params:

NameTypeAttributeDescription
arg_item Instance

Instance item.

Return:

boolean

public has_accepted_type(arg_type: string): boolean source

Test if collection has given accepted type.

Params:

NameTypeAttributeDescription
arg_type string

accepted types string.

Return:

boolean

public item(arg_name: string): Instance | undefined source

Get an item by its name.

Params:

NameTypeAttributeDescription
arg_name string

instance name.

Return:

Instance | undefined

public remove(arg_item: Instance): nothing source

Remove an item from the collection.

Params:

NameTypeAttributeDescription
arg_item Instance

Instance item.

Return:

nothing

public set_accepted_types(arg_types: array): nothing source

Set all collection accepted types.

Params:

NameTypeAttributeDescription
arg_types array

accepted types strings array.

Return:

nothing

public set_all(arg_items: Instance | array): nothing source

Set all collection items.

Params:

NameTypeAttributeDescription
arg_items Instance | array

collection items: one or many Instance objects.

Return:

nothing

public toString(): * source

Format string dump.

@returns{string}

Return:

*

Private Methods

private _add(arg_item: Instance): nothing source

Add an item to the collection without type checks (unsafe).

Params:

NameTypeAttributeDescription
arg_item Instance

Instance item.

Return:

nothing

private _add_first(arg_item: Instance): nothing source

Add an item to the collection without type checks at first position (unsafe).

Params:

NameTypeAttributeDescription
arg_item Instance

Instance item.

Return:

nothing

private _get_all(): array source

Get all collection items.

Return:

array

private _has(arg_item: Instance): boolean source

Test if an item is inside the collection without type checks (unsafe).

Params:

NameTypeAttributeDescription
arg_item Instance

Instance item.

Return:

boolean

private _remove(arg_item: Instance): nothing source

Remove an item from the collection without type checks (unsafe).

Params:

NameTypeAttributeDescription
arg_item Instance

Instance item.

Return:

nothing

private _set_all(arg_items: array): nothing source

Set all collection items.

Params:

NameTypeAttributeDescription
arg_items array

Instance objects array.

Return:

nothing