Source code for radioviz.services.item_counter

#  Copyright 2025–2026 European Union
#  Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)
#  SPDX-License-Identifier: EUPL-1.2
"""
This module provides the ItemCounter class for managing sequential counters.

The ItemCounter class allows for maintaining and incrementing a counter value,
starting from a specified initial value. It's designed to be used in scenarios
where sequential numbering is required, such as generating unique identifiers
or tracking item counts in various applications.
"""


[docs] class ItemCounter: """ A class to manage sequential counting operations. This class maintains an internal counter that can be incremented and retrieved. The counter starts at a specified value and increments by 1 with each call to the :meth:`next` method. :param start_value: The initial value for the counter. Defaults to 1. :type start_value: int """ def __init__(self, start_value: int = 1) -> None: """ Initialize the ItemCounter with a starting value. :param start_value: The initial value for the counter. Defaults to 1. :type start_value: int """ self.counter = start_value self._start_value = start_value @property def count(self) -> int: """ Get the current counter value. :return: The current counter value. :rtype: int """ return self.counter
[docs] def next(self) -> int: """ Increment the counter by one and return the new value. :return: The new counter value after incrementing. :rtype: int """ self.counter += 1 return self.counter
[docs] def reset(self) -> None: """ Reset the counter to its initial value. This method resets the internal counter to the value specified during object initialization. It does not take any parameters and returns nothing. :return: None """ self.counter = self._start_value