Class BinarySimulationWriter<U extends java.io.Serializable,I extends java.io.Serializable,P>
java.lang.Object
es.uam.eps.ir.relison.diffusion.io.backup.BinarySimulationWriter<U,I,P>
- Type Parameters:
U
- Type of the users.I
- Type of the information pieces.P
- Type of the parameters.
- All Implemented Interfaces:
SimulationWriter<U,I,P>
public class BinarySimulationWriter<U extends java.io.Serializable,I extends java.io.Serializable,P> extends java.lang.Object implements SimulationWriter<U,I,P>
Writes a simulation into a file. Data is stored in binary fields,
storing the identifiers of each object.
-
Field Summary
Fields Modifier and Type Field Description private java.io.DataOutputStream
oos
Object output stream for writing into file. -
Constructor Summary
Constructors Constructor Description BinarySimulationWriter()
Constructor. -
Method Summary
Modifier and Type Method Description boolean
close()
Closes the writing objects.boolean
initialize(java.lang.String file)
Initializes the simulation writing.boolean
writeIteration(Simulation<U,I,P> simulation, int numIter)
Writes a single iteration in a file.private boolean
writeReceivedDataUser(Data<U,I,P> data, U u, java.util.Map<I,java.util.Set<U>> infoPieces)
Given a single user, and the data he has received, writes it to a binary fileboolean
writeSimulation(Simulation<U,I,P> simulation)
Writes a whole simulation in a file.private boolean
writeUserActions(Data<U,I,P> data, U u, java.util.List<I> infoPieces)
Given a single user, writes about the information pieces the user has interacted with (propagated or discarded) into a binary file.
-
Field Details
-
oos
private java.io.DataOutputStream oosObject output stream for writing into file.
-
-
Constructor Details
-
BinarySimulationWriter
public BinarySimulationWriter()Constructor.
-
-
Method Details
-
initialize
public boolean initialize(java.lang.String file)Description copied from interface:SimulationWriter
Initializes the simulation writing.- Specified by:
initialize
in interfaceSimulationWriter<U extends java.io.Serializable,I extends java.io.Serializable,P>
- Parameters:
file
- the name of the file where we want to store the simulation.- Returns:
- true if everything went OK, false if something failed while configuring the writer.
-
writeSimulation
Description copied from interface:SimulationWriter
Writes a whole simulation in a file.- Specified by:
writeSimulation
in interfaceSimulationWriter<U extends java.io.Serializable,I extends java.io.Serializable,P>
- Parameters:
simulation
- the simulation.- Returns:
- true if everything went OK, false if something failed while writing.
-
writeIteration
Description copied from interface:SimulationWriter
Writes a single iteration in a file.- Specified by:
writeIteration
in interfaceSimulationWriter<U extends java.io.Serializable,I extends java.io.Serializable,P>
- Parameters:
simulation
- the simulation.numIter
- the iteration number.- Returns:
- true if everything went OK, false if something failed while writing
-
writeReceivedDataUser
private boolean writeReceivedDataUser(Data<U,I,P> data, U u, java.util.Map<I,java.util.Set<U>> infoPieces)Given a single user, and the data he has received, writes it to a binary file- Parameters:
data
- the full data.u
- the user to write.infoPieces
- the set of received information pieces.- Returns:
- true if everything went OK, false if not.
-
writeUserActions
Given a single user, writes about the information pieces the user has interacted with (propagated or discarded) into a binary file.- Parameters:
data
- the full data.u
- the user.infoPieces
- the list of interaction pieces the user has interacted with.- Returns:
- true if everything went OK, false otherwise.
-
close
public boolean close()Description copied from interface:SimulationWriter
Closes the writing objects.- Specified by:
close
in interfaceSimulationWriter<U extends java.io.Serializable,I extends java.io.Serializable,P>
- Returns:
- true if everything went OK, false if something failed while deconfiguring the writer.
-