Package org.powertac.common
Class IdGenerator
- java.lang.Object
-
- org.powertac.common.IdGenerator
-
public class IdGenerator extends Object
Generates numeric ID values for domain types. ID values are of the form xA+B, where x is the multiplier, A is an integer prefix, and B is the value of a counter incremented with each call. The use of a prefix allows the server to give each broker a space of ID values and prevent collisions.- Author:
- John Collins
-
-
Constructor Summary
Constructors Constructor Description IdGenerator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longcreateId()Generates a numeric ID as xA+B.static intextractPrefix(long id)Returns the id prefix for the given id.static intgetMultiplier()Returns the multiplier for an id, needed to validate id valuesstatic intgetPrefix()Returns the id prefix - needed for testing.static StringgetString(long id)Converts ID value to String as A.B.static voidrecycle()Recycles the generator.static voidsetPrefix(int value)Each entity living in a separate process must have a different prefix value.
-
-
-
Method Detail
-
createId
public static long createId()
Generates a numeric ID as xA+B.
-
setPrefix
public static void setPrefix(int value)
Each entity living in a separate process must have a different prefix value. These values are presumably set by the competition control service.
-
getPrefix
public static int getPrefix()
Returns the id prefix - needed for testing.
-
getString
public static String getString(long id)
Converts ID value to String as A.B.
-
getMultiplier
public static int getMultiplier()
Returns the multiplier for an id, needed to validate id values
-
extractPrefix
public static int extractPrefix(long id)
Returns the id prefix for the given id.
-
recycle
public static void recycle()
Recycles the generator. This should only be used in a setting where multiple sessions are run in a single process.
-
-