netunicorn.base.nodes.CountableNodePool

class CountableNodePool(nodes)[source]

Bases: Nodes

Represents a pool of nodes that contains a fixed number of nodes.

Parameters:

nodes (List[Union[Node, Nodes]]) – list of nodes

Attributes

nodes

Nodes in the pool.

Methods

dispatch_and_deserialize

Deserializes a JSON representation of the object and returns an instance of the object.

filter

Returns a pool of nodes that match the given filter function.

from_json

Returns an instance of the object from a JSON representation.

pop

Removes and returns the node at the given index.

set_property

Sets a property for all nodes in the pool.

skip

Returns a pool of nodes consisting of the nodes after the first 'count' nodes.

take

Returns a sequence of nodes consisting of the first count nodes.

nodes[source]

Nodes in the pool.

classmethod from_json(data, metadata=None)[source]

Returns an instance of the object from a JSON representation.

Parameters:
  • data (List[Union[NodeRepresentation, NodesRepresentation]]) – JSON representation of the object

  • metadata (Optional[Any], default: None) – optional additional information for the pool instantiation

Returns:

CountableNodePool – instance of the object

pop(index)[source]

Removes and returns the node at the given index.

Parameters:

index (int) – index of the node to remove

Returns:

Union[Node, Nodes] – popped node

filter(function)[source]

Returns a pool of nodes that match the given filter function.

Parameters:

function (Callable[[Node], bool]) – filter function returning True if the node should be included in the result

Returns:

CountableNodePool – pool of nodes

take(count)[source]

Returns a sequence of nodes consisting of the first count nodes.

Parameters:

count (int) – number of nodes to take

Returns:

Sequence[Node] – sequence of nodes

skip(count)[source]

Returns a pool of nodes consisting of the nodes after the first ‘count’ nodes.

Parameters:

count (int) – number of nodes to skip

Returns:

CountableNodePool – pool of nodes

set_property(name, value)[source]

Sets a property for all nodes in the pool.

Parameters:
  • name (str) – name of the property

  • value (Union[str, float, int, Set[str], None]) – property value

Returns:

CountableNodePool – self

static dispatch_and_deserialize(data)[source]

Deserializes a JSON representation of the object and returns an instance of the object.

Parameters:

data (NodesRepresentation) – JSON representation of the object

Returns:

Nodes – instance of the object