Class InMemoryInstanceHandler
- java.lang.Object
-
- org.spectrumauctions.sats.core.util.instancehandling.InstanceHandler
-
- org.spectrumauctions.sats.core.util.instancehandling.InMemoryInstanceHandler
-
public class InMemoryInstanceHandler extends InstanceHandler
A fast instance handler implementation.
No files are written - all write methods are empty mocks.
The use of this handler is only recommended if no instances are serialized or deserialized.
Otherwise, id collisions may occure.- Author:
- Michael Weiss
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static InMemoryInstanceHandlergetInstance()longgetNextPopulationId(long worldId)Returns a new population id The id is unique amongst all previously generated population ids with the same worldId.longgetNextWorldId()Returns an new unused world id.java.util.Collection<java.lang.Long>getPopulationIds(long worldId)<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 known<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.<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<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.<T extends World>
TreadWorld(java.lang.Class<T> type, long world)Reads a world instance.voidwriteBidder(SATSBidder bidder)Writes a new bidder instance.voidwriteWorld(World world)Writes a world instance.-
Methods inherited from class org.spectrumauctions.sats.core.util.instancehandling.InstanceHandler
getDefaultHandler, setDefaultHandler
-
-
-
-
Method Detail
-
getInstance
public static InMemoryInstanceHandler getInstance()
-
writeWorld
public void writeWorld(World world)
Description copied from class:InstanceHandlerWrites a world instance. If a world with the same id already is stored, it might be overwritten.- Specified by:
writeWorldin classInstanceHandler- Parameters:
world- the world to be written
-
writeBidder
public void writeBidder(SATSBidder bidder)
Description copied from class:InstanceHandlerWrites a new bidder instance. If a bidder with the same world and population id already is stored, it might be overwritten.- Specified by:
writeBidderin classInstanceHandler- Parameters:
bidder- the bidder to be written
-
getPopulationIds
public java.util.Collection<java.lang.Long> getPopulationIds(long worldId)
- Specified by:
getPopulationIdsin classInstanceHandler- Returns:
- A collection containing all ids of the stored population for the requested world
-
readBidder
public <T extends SATSBidder> T readBidder(java.lang.Class<T> type, World world, long populationId, long bidderId)
Description copied from class:InstanceHandlerUsed to deserialize a bidder, if its implementing class is known- Specified by:
readBidderin classInstanceHandler- 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
-
readPopulation
public <T extends SATSBidder> java.util.Collection<T> readPopulation(java.lang.Class<T> type, World world, long populationId)
Description copied from class:InstanceHandlerUsed to deserialize a set of bidders, if the implementing class of all bidders is known and the same- Specified by:
readPopulationin classInstanceHandler- 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
-
readBidderWithUnknownType
public <T extends SATSBidder> T readBidderWithUnknownType(java.lang.Class<T> bidderSuperType, World world, long populationId, long bidderId)
Description copied from class:InstanceHandlerUsed to deserialize a bidder, if its type is not exactly known, i.e., if there are different bidder implementations for this model.- Specified by:
readBidderWithUnknownTypein classInstanceHandler- 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
-
readPopulationWithUnknownTypes
public <T extends SATSBidder> java.util.List<T> readPopulationWithUnknownTypes(java.lang.Class<T> bidderSuperType, World world, long populationId)
Description copied from class:InstanceHandlerUsed to deserialize a set of bidders, if their type is not exactly known, i.e., if there are different bidder implementations for this model.- Specified by:
readPopulationWithUnknownTypesin classInstanceHandler- 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 long getNextWorldId()
Description copied from class:InstanceHandlerReturns an new unused world id. The id is unique amongst all previously generated world ids.- Specified by:
getNextWorldIdin classInstanceHandler- Returns:
- an unused world id
-
getNextPopulationId
public long getNextPopulationId(long worldId)
Description copied from class:InstanceHandlerReturns a new population id The id is unique amongst all previously generated population ids with the same worldId.- Specified by:
getNextPopulationIdin classInstanceHandler- Parameters:
worldId- The id of the world to which the new population will belong- Returns:
- a new population id
-
readWorld
public <T extends World> T readWorld(java.lang.Class<T> type, long world)
Description copied from class:InstanceHandlerReads a world instance.- Specified by:
readWorldin classInstanceHandler
-
-