Class SequenceNumberService


  • public class SequenceNumberService
    extends Object
    Manage series (identified by their name) of positive (i.e., starting with 1) consecutive integers. This class is usually instantiated via the static method getFor(Simulation) to access a single instance for a given simulation. Internally the simulation's ValueStore is used to store the instance.
    Author:
    Torsten Hildebrandt
    • Constructor Detail

      • SequenceNumberService

        public SequenceNumberService()
        Parameterless constructor. Usually you will use the method getFor(Simulation) to (re-)use a global instance of this class associated with a certain simulation.
    • Method Detail

      • getFor

        public static SequenceNumberService getFor​(Simulation sim)
        Returns the instance of this class associated with the given simulation. If no such instance exists, a new one will be created and stored in the simulation's valueStore to be picked up by later calls to this method.
      • nextValue

        public int nextValue​(String key)
        Looks up the next value associated with key. If "key" is used for the first time, 1 will be returned.
        Parameters:
        key - The key to use (musn't be null).
        Returns:
        The next value to use or "key".
      • nextFormattedValue

        public String nextFormattedValue​(String key)
        Returns a String consisting of the key and the next value in the sequence, separated by '-'. This means, calling this method for the key "job" would result in "job-1" where the number at the end is the value returned by nextValue(String).
        Parameters:
        key - The name to use.
        Returns:
        A formatted String containing the key, a single dash and the sequence number.
      • get

        public int get​(String key)
        Returns the last value returned for "key", i.e., the last value returned by nextValue(String) for this key. If the key was not used before, then -1 will be returned.
      • set

        public void set​(String key,
                        int startValue)
        Explicitly sets the current value associated with a certain key. The value used will be returned by the next call to nextValue(String) for this key.

        To create a series starting by "1" this method does not have to be called, just start calling nextValue(String).

        Parameters:
        key - the name to use for the series, mustn't be null.
        startValue - the next value to return for the series, mustn't be negative
        Throws:
        IllegalArgumentException - if either key was null or startValue was <0