org.decisiondeck.jmcda.persist.text
Class MahdiExporter

java.lang.Object
  extended by org.decisiondeck.jmcda.persist.text.MahdiExporter

public class MahdiExporter
extends Object

A class to export sorting assignments data to a format called Mahdi format, after the name of a colleague who uses it. This is a text format, tab separated, based on Comma Separated Values (CSV), although not exactly conformant to CSV. The exported data contain only numbers, and is encoded in US-ASCII. This is an easy format that may be used to work with someone who does not like parsing xml. XML format should be preferred in other cases, because it is much more expressive, more general, (approximately) self-documenting, etc. The file extension "MHF", for Mahdi Format, has been chosen because it does not seem to collide too much with much used extensions.

This format may be used only with criteria whose preference direction is Criterion.PreferenceDirection.MAXIMIZE.

This exporter expects to receive an input data object representing the data to export and an output directory. A directory is expected because several files may be created. The files are named after the constants defined in this class. An alternative is to give it specific Writer objects for each file to write.

The format is based on indexing the criteria and alternatives from zero to the number of criteria, resp. alternatives. The format consists of a file "ga" which describes the alternatives performances over the criteria, this is a usual CSV format (except it is tab separated) with the line i describing the performances of the alternative i, the column j containing the evaluation of the alternatives on the jth criterion. An other file, "e", describes the assignments of the decision makers. The decision makers are indexed from zero. A line contains the decision maker id, then a set of pairs follows with the id of an alternative assigned by this decision maker followed by the id of the category (indexed from zero, the worst category) to which the alternative is assigned.

This object maps alternatives, decision makers, criteria to indexes from zero by ordering them using their natural ordering, then assigning indexes from zero in the iteration order. Note that natural ordering is alphabetical, not numerical, thus if the alternatives (e.g.) are named "1", "2", etc., the alternative "10" will come before alternative "2" and thus "1" will correspond to index 0, "10" to index 1, "11" to index 2, "19" to index 10, "2" to index 11, etc. This can be confusing. A better way is to name your alternatives (and criteria, decision makers) "0000" (note the start from zero), "0001", etc., or with a constant prefix "Alt000", etc. Naturally this exporter works with any names, although some are more intuitively converted to ids than others. The categories are indexed from 0 starting from the worst one, irrespective of their names.

Note that as this exporter changes the order of the given input to make sure it is exported in the correct order, to ensure the output is consistent if the result of this export is to be accompanied with other data, make sure the order of these other data reflect the order used here. It is suggested to use getInputData() and getExportSettings() on this object after having set the input as this will make sure the caller uses the same order and settings as this object.


Field Summary
static String FILE_NAME_E
           
static String FILE_NAME_GA
           
 
Constructor Summary
MahdiExporter()
           
 
Method Summary
 ExportSettings getExportSettings()
           Input data must have been set.
 IGroupSortingAssignments getInputData()
          Retrieves the data set as input with an order reflecting the order required for export (thus possibly changed compared to the input set).
 File getOutputDirectory()
           
 Writer getWriterE()
           
 Writer getWriterGa()
           
 void setInputData(IGroupSortingAssignments inputData)
           
 void setOutputDirectory(File outputDirectory)
           
 void setWriterE(Writer writerE)
           
 void setWriterGa(Writer writerGa)
           
 void write()
           Both writers E and Ga must be set, or the output directory must be set.
 void writeE()
           The appropriate writer must be set, or the output directory must be set.
 void writeGa()
           The appropriate writer must be set, or the output directory must be set.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_NAME_E

public static final String FILE_NAME_E
See Also:
Constant Field Values

FILE_NAME_GA

public static final String FILE_NAME_GA
See Also:
Constant Field Values
Constructor Detail

MahdiExporter

public MahdiExporter()
Method Detail

getOutputDirectory

public File getOutputDirectory()
Returns:
null iff no output directory set.

setOutputDirectory

public void setOutputDirectory(File outputDirectory)
Parameters:
outputDirectory - null for no output directory set (forbids this object to create writers).

getInputData

public IGroupSortingAssignments getInputData()
Retrieves the data set as input with an order reflecting the order required for export (thus possibly changed compared to the input set). The returned object is immutable.

Returns:
null iff no input set.

setInputData

public void setInputData(IGroupSortingAssignments inputData)
Parameters:
inputData - not null.

write

public void write()
           throws IOException,
                  InvalidInputException

Both writers E and Ga must be set, or the output directory must be set.

Writes the streams E and Ga (see this class' documentation) to the appropriate writer set by the user. If some writer has not been defined, creates a new file in the output directory precedingly given. If this object creates writers, it closes them after use. Any writer given by the user of this object are not closed by this object.

If some writer is not set by the user, this method creates directories if necessary before creating the writer.

Throws:
IOException - if an error occurs when creating the writer or while writing data to the destination stream or while closing the stream.
InvalidInputException - iff the set of alternatives evaluations contained in the input data is not complete..

writeGa

public void writeGa()
             throws IOException,
                    InvalidInputException

The appropriate writer must be set, or the output directory must be set.

Writes the data stream Ga (see this class' documentation) to the appropriate writer set by the user. If some writer has not been defined, creates a new file in the output directory precedingly given. If this object creates a writer, it closes it after use. Any writer given by the user of this object are not closed by this object.

If the writer is not set by the user, this method creates required directories if necessary before creating the writer.

Throws:
IOException - if an error occurs when creating the writer or while writing data to the destination stream or while closing the stream.
InvalidInputException - iff the set of alternatives evaluations contained in the input data is not complete.

writeE

public void writeE()
            throws IOException

The appropriate writer must be set, or the output directory must be set.

Writes the stream E (see this class' documentation) to the appropriate writer set by the user. If some writer has not been defined, creates a new file in the output directory precedingly given. If this object creates writers, it closes them after use. Any writer given by the user of this object are not closed by this object.

If the writer is not set by the user, this method creates directories if necessary before creating the writer.

Throws:
IOException - if an error occurs when creating the writer or while writing data to the destination stream or while closing the stream.

getWriterE

public Writer getWriterE()
Returns:
null iff no such user defined writer.

setWriterE

public void setWriterE(Writer writerE)

getWriterGa

public Writer getWriterGa()
Returns:
null iff no such user defined writer.

setWriterGa

public void setWriterGa(Writer writerGa)

getExportSettings

public ExportSettings getExportSettings()

Input data must have been set.

Retrieves the export settings used by this object.

Returns:
not null.


Copyright © 2011. All Rights Reserved.