de.fu_berlin.ties.eval
Class ShuffleGenerator

java.lang.Object
  extended by de.fu_berlin.ties.ConfigurableProcessor
      extended by de.fu_berlin.ties.CollectingProcessor
          extended by de.fu_berlin.ties.eval.ShuffleGenerator
All Implemented Interfaces:
Closeable, Processor

public class ShuffleGenerator
extends CollectingProcessor

Arranges all input arguments (for example, files or URLs) in random "shuffles", so they can subsequently processed in random (but fixed) order. This helps generating input data for experiments. Each random shuffle will be stored in a file; each line of the file will contain one of the input arguments; the order of input arguments will be random. If the input arguments are URIs/URLs, this format correspondings to the text/uri-list media type defined in RFC 2483; it can be read using the IOUtils.readURIList(CharSequence) methods.

Also contains the static shuffle(List) method so it can be used as a static utility class.

Version:
$Revision: 1.9 $, $Date: 2006/10/21 16:04:11 $, $Author: siefkes $
Author:
Christian Siefkes

Constructor Summary
ShuffleGenerator()
          Creates a new instance from the standard configuration.
ShuffleGenerator(int firstNum, int num, String filePrefix, String fileExt, TiesConfiguration conf)
          Creates a new instance from the provided configuration.
ShuffleGenerator(TiesConfiguration conf)
          Creates a new instance from the provided configuration.
 
Method Summary
 void process(List<String> collected, ContextMap context)
          Processes the collected input arguments.
static
<T> List<T>
shuffle(List<T> input)
          Static utility method that "shuffles" a list by re-arranging its elements in random order.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class de.fu_berlin.ties.CollectingProcessor
close, process
 
Methods inherited from class de.fu_berlin.ties.ConfigurableProcessor
getConfig
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ShuffleGenerator

public ShuffleGenerator()
Creates a new instance from the standard configuration.


ShuffleGenerator

public ShuffleGenerator(TiesConfiguration conf)
Creates a new instance from the provided configuration.

Parameters:
conf - used to configure this instance; must not be null

ShuffleGenerator

public ShuffleGenerator(int firstNum,
                        int num,
                        String filePrefix,
                        String fileExt,
                        TiesConfiguration conf)
Creates a new instance from the provided configuration. Generated shuffle files will be named from filePrefixNUMBER.fileExt, where NUMBER is a number from firstNum to firstNum + num - 1; if necessary, numbers will be padded with leading zeros so all numbers are of the same length (e.g. 01 to 10).

Parameters:
firstNum - The number used in the name of the first generated shuffle file (typically 1)
num - The number of random shuffles to generate
filePrefix - Prefix used for the generated random shuffle files
fileExt - Extension used for the generated random shuffle files
conf - passed to the superclass; if null, the standard configuration is used
Method Detail

shuffle

public static <T> List<T> shuffle(List<T> input)
Static utility method that "shuffles" a list by re-arranging its elements in random order. The original list will be destroyed by this method (i.e. it might be empty after this method returns)! It is recommended to pass a LinkedList (and not a ArrayList) as input argument because iteratively deleting elements from ArrayLists is very inefficient.

Type Parameters:
T - the type of the list
Parameters:
input - the list of elements to shuffle; should be a LinkedList for efficiency; will be destroyed by this method (i.e. it might be empty after this method returns)
Returns:
a new list containing the elements of the input in random order

process

public void process(List<String> collected,
                    ContextMap context)
             throws IOException
Processes the collected input arguments.

Specified by:
process in class CollectingProcessor
Parameters:
collected - a list of Strings containing the collected input arguments
context - a map of objects that are made available for processing; will be empty when called from the CollectingProcessor.close(int) method in this class
Throws:
IOException - if an I/O error occurs

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a textual representation


Copyright © 2003-2007 Christian Siefkes. All Rights Reserved.