Class InstanceHandler
- java.lang.Object
-
- org.spectrumauctions.sats.core.util.instancehandling.InstanceHandler
-
- Direct Known Subclasses:
InMemoryInstanceHandler,JSONInstanceHandler
public abstract class InstanceHandler extends java.lang.Object- Author:
- Michael Weiss
-
-
Constructor Summary
Constructors Constructor Description InstanceHandler()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static InstanceHandlergetDefaultHandler()Get the default instance handler.abstract longgetNextPopulationId(long worldId)Returns a new population id The id is unique amongst all previously generated population ids with the same worldId.abstract longgetNextWorldId()Returns an new unused world id.abstract java.util.Collection<java.lang.Long>getPopulationIds(long worldId)abstract <T extends SATSBidder>
TreadBidder(java.lang.Class<T> type, World world, long populationId, long bidderId)Used to deserialize a bidder, if its implementing class is knownabstract <T extends SATSBidder>
TreadBidderWithUnknownType(java.lang.Class<T> bidderSuperType, World world, long populationId, long bidderId)Used to deserialize a bidder, if its type is not exactly known, i.e., if there are different bidder implementations for this model.abstract <T extends SATSBidder>
java.util.Collection<T>readPopulation(java.lang.Class<T> type, World world, long populationId)Used to deserialize a set of bidders, if the implementing class of all bidders is known and the sameabstract <T extends SATSBidder>
java.util.List<T>readPopulationWithUnknownTypes(java.lang.Class<T> bidderSuperType, World world, long populationId)Used to deserialize a set of bidders, if their type is not exactly known, i.e., if there are different bidder implementations for this model.abstract <T extends World>
TreadWorld(java.lang.Class<T> type, long world)Reads a world instance.static voidsetDefaultHandler(InstanceHandler defaultHandler)Set a new default instance handler.
The default instance handler is called on everyWorld, population andSATSBiddercreation for id selection and default storing.abstract voidwriteBidder(SATSBidder bidder)Writes a new bidder instance.abstract voidwriteWorld(World world)Writes a world instance.
-
-
-
Method Detail
-
getDefaultHandler
public static InstanceHandler getDefaultHandler()
Get the default instance handler.
The default instance handler is called on everyWorld, population andSATSBiddercreation for id selection and default storing.- Returns:
- the default instance handler
-
setDefaultHandler
public static void setDefaultHandler(InstanceHandler defaultHandler)
Set a new default instance handler.
The default instance handler is called on everyWorld, population andSATSBiddercreation for id selection and default storing.- Parameters:
defaultHandler- the new default instance handler
-
writeWorld
public abstract void writeWorld(World world)
Writes a world instance. If a world with the same id already is stored, it might be overwritten.- Parameters:
world- the world to be written
-
readWorld
public abstract <T extends World> T readWorld(java.lang.Class<T> type, long world)
Reads a world instance.
-
writeBidder
public abstract void writeBidder(SATSBidder bidder)
Writes a new bidder instance. If a bidder with the same world and population id already is stored, it might be overwritten.- Parameters:
bidder- the bidder to be written
-
getPopulationIds
public abstract java.util.Collection<java.lang.Long> getPopulationIds(long worldId)
- Returns:
- A collection containing all ids of the stored population for the requested world
-
readBidder
public abstract <T extends SATSBidder> T readBidder(java.lang.Class<T> type, World world, long populationId, long bidderId)
Used to deserialize a bidder, if its implementing class is known- Parameters:
type- the class of which a new instance should be createdworld- the world the bidder lives inpopulationId- the id of the populationbidderId- the id of the bidder- Returns:
- the deserialized bidder
-
readBidderWithUnknownType
public abstract <T extends SATSBidder> T readBidderWithUnknownType(java.lang.Class<T> bidderSuperType, World world, long populationId, long bidderId)
Used to deserialize a bidder, if its type is not exactly known, i.e., if there are different bidder implementations for this model.- Parameters:
bidderSuperType- the deserialized bidder is either of class bidderSuperType or of a subclass of bidderSuperTypeworld- the world the bidder lives inpopulationId- the id of the populationbidderId- the id of the bidder- Returns:
- the deserialized bidder
-
readPopulation
public abstract <T extends SATSBidder> java.util.Collection<T> readPopulation(java.lang.Class<T> type, World world, long populationId)
Used to deserialize a set of bidders, if the implementing class of all bidders is known and the same- Parameters:
type- the class of which the new bidder instances should be createdworld- the world the bidders live inpopulationId- the id of the population- Returns:
- the deserialized bidders
-
readPopulationWithUnknownTypes
public abstract <T extends SATSBidder> java.util.List<T> readPopulationWithUnknownTypes(java.lang.Class<T> bidderSuperType, World world, long populationId)
Used to deserialize a set of bidders, if their type is not exactly known, i.e., if there are different bidder implementations for this model.- Parameters:
bidderSuperType- the deserialized bidder is either of class bidderSuperType or of a subclass of bidderSuperTypeworld- the world the bidders live inpopulationId- the id of the population- Returns:
- the deserialized bidders
-
getNextWorldId
public abstract long getNextWorldId()
Returns an new unused world id. The id is unique amongst all previously generated world ids.- Returns:
- an unused world id
-
getNextPopulationId
public abstract long getNextPopulationId(long worldId)
Returns a new population id The id is unique amongst all previously generated population ids with the same worldId.- Parameters:
worldId- The id of the world to which the new population will belong- Returns:
- a new population id
-
-