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.DataOutputStreamoosObject output stream for writing into file. -
Constructor Summary
Constructors Constructor Description BinarySimulationWriter()Constructor. -
Method Summary
Modifier and Type Method Description booleanclose()Closes the writing objects.booleaninitialize(java.lang.String file)Initializes the simulation writing.booleanwriteIteration(Simulation<U,I,P> simulation, int numIter)Writes a single iteration in a file.private booleanwriteReceivedDataUser(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 filebooleanwriteSimulation(Simulation<U,I,P> simulation)Writes a whole simulation in a file.private booleanwriteUserActions(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:SimulationWriterInitializes the simulation writing.- Specified by:
initializein 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:SimulationWriterWrites a whole simulation in a file.- Specified by:
writeSimulationin 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:SimulationWriterWrites a single iteration in a file.- Specified by:
writeIterationin 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:SimulationWriterCloses the writing objects.- Specified by:
closein 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.
-