List

class List(client, service_name, name)

Bases: hazelcast.proxy.base.PartitionSpecificProxy

Concurrent, distributed implementation of List.

The Hazelcast List is not a partitioned data-structure. So all the content of the List is stored in a single machine (and in the backup). So the List will not scale by adding more members in the cluster.

add(item)

Adds the specified item to the end of this list.

Parameters:item – (object), the specified item to be appended to this list.
Returns:(bool), true if item is added, false otherwise.
add_at(index, item)

Adds the specified item at the specific position in this list. Element in this position and following elements are shifted to the right, if any.

Parameters:
  • index – (int), the specified index to insert the item.
  • item – (object), the specified item to be inserted.
add_all(items)

Adds all of the items in the specified collection to the end of this list. The order of new elements is determined by the specified collection’s iterator.

Parameters:items – (Collection), the specified collection which includes the elements to be added to list.
Returns:(bool), true if this call changed the list, false otherwise.
add_all_at(index, items)

Adds all of the elements in the specified collection into this list at the specified position. Elements in this positions and following elements are shifted to the right, if any. The order of new elements is determined by the specified collection’s iterator.

Parameters:
  • index – (int), the specified index at which the first element of specified collection is added.
  • items – (Collection), the specified collection which includes the elements to be added to list.
Returns:

(bool), true if this call changed the list, false otherwise.

add_listener(include_value=False, item_added_func=None, item_removed_func=None)

Adds an item listener for this list. Listener will be notified for all list add/remove events.

Parameters:
  • include_value – (bool), whether received events include the updated item or not (optional).
  • item_added_func – Function to be called when an item is added to this list (optional).
  • item_removed_func – Function to be called when an item is deleted from this list (optional).
Returns:

(str), a registration id which is used as a key to remove the listener.

clear()

Clears the list. List will be empty with this call.

contains(item)

Determines whether this list contains the specified item or not.

Parameters:item – (object), the specified item.
Returns:(bool), true if the specified item exists in this list, false otherwise.
contains_all(items)

Determines whether this list contains all of the items in specified collection or not.

Parameters:items – (Collection), the specified collection which includes the items to be searched.
Returns:(bool), true if all of the items in specified collection exist in this list, false otherwise.
get(index)

Returns the item which is in the specified position in this list.

Parameters:index – (int), the specified index of the item to be returned.
Returns:(object), the item in the specified position in this list.
get_all()

Returns all of the items in this list.

Returns:(Sequence), list that includes all of the items in this list.
iterator()

Returns an iterator over the elements in this list in proper sequence, same with get_all().

Returns:(Sequence), an iterator over the elements in this list in proper sequence.
index_of(item)

Returns the first index of specified items’s occurrences in this list. If specified item is not present in this list, returns -1.

Parameters:item – (object), the specified item to be searched for.
Returns:(int), the first index of specified items’s occurrences, -1 if item is not present in this list.
is_empty()

Determines whether this list is empty or not.

Returns:(bool), true if this list contains no elements.
last_index_of(item)

Returns the last index of specified items’s occurrences in this list. If specified item is not present in this list, returns -1.

Parameters:item – (object), the specified item to be searched for.
Returns:(int), the last index of specified items’s occurrences, -1 if item is not present in this list.
list_iterator(index=0)

Returns a list iterator of the elements in this list. If an index is provided, iterator starts from this index.

Parameters:index – (int), index of first element to be returned from the list iterator (optional).
Returns:(Sequence), a list iterator of the elements in this list.
remove(item)

Removes the specified element’s first occurrence from the list if it exists in this list.

Parameters:item – (object), the specified element.
Returns:(bool), true if the specified element is present in this list.
remove_at(index)

Removes the item at the specified position in this list. Element in this position and following elements are shifted to the left, if any.

Parameters:index – (int), index of the item to be removed.
Returns:(object), the item previously at the specified index.
remove_all(items)

Removes all of the elements that is present in the specified collection from this list.

Parameters:items – (Collection), the specified collection.
Returns:(bool), true if this list changed as a result of the call.
remove_listener(registration_id)

Removes the specified item listener. Returns silently if the specified listener was not added before.

Parameters:registration_id – (str), id of the listener to be deleted.
Returns:(bool), true if the item listener is removed, false otherwise.
retain_all(items)

Retains only the items that are contained in the specified collection. It means, items which are not present in the specified collection are removed from this list.

Parameters:items – (Collection), collections which includes the elements to be retained in this list.
Returns:(bool), true if this list changed as a result of the call.
size()

Returns the number of elements in this list.

Returns:(int), number of the elements in this list.
set_at(index, item)

Replaces the specified element with the element at the specified position in this list.

Parameters:
  • index – (int), index of the item to be replaced.
  • item – (object), item to be stored.
Returns:

(object), the previous item in the specified index.

sub_list(from_index, to_index)

Returns a sublist from this list, whose range is specified with from_index(inclusive) and to_index(exclusive). The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa.

Parameters:
  • from_index – (int), the start point(inclusive) of the sub_list.
  • to_index – (int), th end point(exclusive) of the sub_list.
Returns:

(Sequence), a view of the specified range within this list.