public static void main(final String[] arg) throws IOException, ClassNotFoundException, JSAPException {
SimpleJSAP jsap = new SimpleJSAP(PermutedFrontCodedStringList.class.getName(), "Builds a permuted front-coded list of strings using a given front-coded string list and a permutation (either in text or binary format).",
new Parameter[] {
new Switch("invert", 'i', "invert", "Invert permutation before creating the permuted list."),
new Switch("text", 't', "text", "The permutation is a text file."),
new UnflaggedOption("list", JSAP.STRING_PARSER, JSAP.REQUIRED, "A front-coded string list."),
new UnflaggedOption("permutation", JSAP.STRING_PARSER, JSAP.REQUIRED, "A permutation for the indices of the list (in DataInput format, unless you specify --text)."),
new UnflaggedOption("permutedList", JSAP.STRING_PARSER, JSAP.REQUIRED, "A the filename for the resulting permuted list."),
});
JSAPResult jsapResult = jsap.parse(arg);
if (jsap.messagePrinted()) return;
final String permutationFile = jsapResult.getString("permutation");
final int[] permutation = jsapResult.userSpecified("text")
? IntIterators.unwrap(TextIO.asIntIterator(permutationFile))
: BinIO.loadInts(permutationFile);
if (jsapResult.getBoolean("invert")) Util.invertPermutationInPlace(permutation);
BinIO.storeObject(
new PermutedFrontCodedStringList((FrontCodedStringList)BinIO.loadObject(jsapResult.getString("list")), permutation),
jsapResult.getString("permutedList")
);
}
}