Class JSONInstanceHandler


  • public class JSONInstanceHandler
    extends InstanceHandler
    Author:
    Michael Weiss
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static JSONInstanceHandler getInstance()  
      long getNextPopulationId​(long worldId)
      Returns a new population id The id is unique amongst all previously generated population ids with the same worldId.
      long getNextWorldId()
      Returns an new unused world id.
      java.util.Collection<java.lang.Long> getPopulationIds​(long worldId)  
      <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
      <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.
      <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>
      T
      readWorld​(java.lang.Class<T> type, long worldId)
      Reads a world instance.
      void writeBidder​(SATSBidder bidder)
      Writes a new bidder instance.
      void writeWorld​(World world)
      Writes a world instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • writeWorld

        public void writeWorld​(World world)
        Description copied from class: InstanceHandler
        Writes a world instance. If a world with the same id already is stored, it might be overwritten.
        Specified by:
        writeWorld in class InstanceHandler
        Parameters:
        world - the world to be written
      • writeBidder

        public void writeBidder​(SATSBidder bidder)
        Description copied from class: InstanceHandler
        Writes a new bidder instance. If a bidder with the same world and population id already is stored, it might be overwritten.
        Specified by:
        writeBidder in class InstanceHandler
        Parameters:
        bidder - the bidder to be written
      • getPopulationIds

        public java.util.Collection<java.lang.Long> getPopulationIds​(long worldId)
        Specified by:
        getPopulationIds in class InstanceHandler
        Returns:
        A collection containing all ids of the stored population for the requested world
      • readBidderWithUnknownType

        public <T extends SATSBidder> T readBidderWithUnknownType​(java.lang.Class<T> bidderSuperType,
                                                                  World world,
                                                                  long populationId,
                                                                  long bidderId)
        Description copied from class: InstanceHandler
        Used to deserialize a bidder, if its type is not exactly known, i.e., if there are different bidder implementations for this model.
        Specified by:
        readBidderWithUnknownType in class InstanceHandler
        Parameters:
        bidderSuperType - the deserialized bidder is either of class bidderSuperType or of a subclass of bidderSuperType
        world - the world the bidder lives in
        populationId - the id of the population
        bidderId - the id of the bidder
        Returns:
        the deserialized bidder
      • readBidder

        public <T extends SATSBidder> T readBidder​(java.lang.Class<T> type,
                                                   World world,
                                                   long populationId,
                                                   long bidderId)
        Description copied from class: InstanceHandler
        Used to deserialize a bidder, if its implementing class is known
        Specified by:
        readBidder in class InstanceHandler
        Parameters:
        type - the class of which a new instance should be created
        world - the world the bidder lives in
        populationId - the id of the population
        bidderId - 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: InstanceHandler
        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.
        Specified by:
        readPopulationWithUnknownTypes in class InstanceHandler
        Parameters:
        bidderSuperType - the deserialized bidder is either of class bidderSuperType or of a subclass of bidderSuperType
        world - the world the bidders live in
        populationId - the id of the population
        Returns:
        the deserialized bidders
      • readPopulation

        public <T extends SATSBidder> java.util.Collection<T> readPopulation​(java.lang.Class<T> type,
                                                                             World world,
                                                                             long populationId)
        Description copied from class: InstanceHandler
        Used to deserialize a set of bidders, if the implementing class of all bidders is known and the same
        Specified by:
        readPopulation in class InstanceHandler
        Parameters:
        type - the class of which the new bidder instances should be created
        world - the world the bidders live in
        populationId - the id of the population
        Returns:
        the deserialized bidders
      • getNextWorldId

        public long getNextWorldId()
        Description copied from class: InstanceHandler
        Returns an new unused world id. The id is unique amongst all previously generated world ids.
        Specified by:
        getNextWorldId in class InstanceHandler
        Returns:
        an unused world id
      • getNextPopulationId

        public long getNextPopulationId​(long worldId)
        Description copied from class: InstanceHandler
        Returns a new population id The id is unique amongst all previously generated population ids with the same worldId.
        Specified by:
        getNextPopulationId in class InstanceHandler
        Parameters:
        worldId - The id of the world to which the new population will belong
        Returns:
        a new population id