Package jasima.core.util
Class SequenceNumberService
- java.lang.Object
-
- jasima.core.util.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 methodgetFor(Simulation)to access a single instance for a given simulation. Internally the simulation'sValueStoreis used to store the instance.- Author:
- Torsten Hildebrandt
-
-
Constructor Summary
Constructors Constructor Description SequenceNumberService()Parameterless constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intget(String key)Returns the last value returned for "key", i.e., the last value returned bynextValue(String)for this key.static SequenceNumberServicegetFor(Simulation sim)Returns the instance of this class associated with the given simulation.StringnextFormattedValue(String key)Returns a String consisting of the key and the next value in the sequence, separated by '-'.intnextValue(String key)Looks up the next value associated with key.voidset(String key, int startValue)Explicitly sets the current value associated with a certain key.
-
-
-
Constructor Detail
-
SequenceNumberService
public SequenceNumberService()
Parameterless constructor. Usually you will use the methodgetFor(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 bynextValue(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 bynextValue(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 tonextValue(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 eitherkeywas null orstartValuewas <0
-
-