API Docs for:
Show:

Utils.Bag Class

Defined in: ../src/utils/Bag.js:4
Module: Utils
Parent Module: ArtemiJS

Collection type a bit like ArrayList but does not preserve the order of its entities, speedwise it is very good, especially suited for games.

Methods

add

(
  • Mixed
)

Adds the specified element to the end of this bag. if needed also increases the capacity of the bag.

Parameters:

  • Mixed Object

    element to be added to this list

addAll

(
  • bag
)

Add all items into this bag.

Parameters:

  • bag Bag

    added

capacity

() Number

Returns the number of elements the bag can hold without growing.

Returns:

Number: the number of elements the bag can hold without growing.

clear

()

Removes all of the elements from this bag. The bag will be empty after this call returns.

contains

(
  • Mixed
)

Check if bag contains this element.

Parameters:

  • Mixed Object

Returns:

Mixed

ensureCapacity

(
  • index
)

Method verify the capacity of the bag

Parameters:

  • index Number

get

(
  • index
)

Returns the element at the specified position in Bag.

Parameters:

  • index Number

    index of the element to return

Returns:

Mixed the element at the specified position in bag

isEmpty

() Boolean

Returns true if this list contains no elements.

Returns:

Boolean: true if is empty, else false

isIndexWithinBounds

(
  • index
)
Boolean

Checks if the internal storage supports this index.

Parameters:

  • index Number

Returns:

Boolean:

remove

(
  • Mixed
)

Removes the element at the specified position in this Bag. does this by overwriting it was last element then removing last element

Parameters:

  • Mixed Object

    index the index of element to be removed

Returns:

Mixed element that was removed from the Bag

removeAll

(
  • Bag
)
Boolean

Removes from this Bag all of its elements that are contained in the specified Bag.

Parameters:

  • Bag Bag

    containing elements to be removed from this Bag

Returns:

Boolean: true if this Bag changed as a result of the call, else false

removeLast

()

Remove and return the last object in the bag.

Returns:

Mixed the last object in the bag, null if empty.

set

(
  • index
  • Mixed
)

Set element at specified index in the bag.

Parameters:

  • index Number

    position of element

  • Mixed Object

    the element

size

() Number

Returns the number of elements in this bag.

Returns:

Number: the number of elements in this bag

Properties

data

Array private

Contains all of the elements