Example usage for java.lang IllegalArgumentException printStackTrace

List of usage examples for java.lang IllegalArgumentException printStackTrace

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException printStackTrace.

Prototype

public void printStackTrace(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:edu.nyu.tandon.tool.BinnedRawHits.java

/**
 * Interpret the given command, changing the static variables.
 * See the help printing code for possible commands.
 *
 * @param line the command line./*ww w.jav a  2 s .co m*/
 * @return false iff we should exit after this command.
 */
public boolean interpretCommand(final String line) {
    String[] part = line.substring(1).split("[ \t\n\r]+");

    final Command command;
    int i;

    if (part[0].length() == 0) {
        System.err.println("$                                                       prints this help.");
        System.err.println("$mode [time|short|long|snippet|trec <topicNo> <runTag>] chooses display mode.");
        System.err.println(
                "$limit <max>                                            output at most <max> results per query.");
        System.err.println(
                "$divert [<filename>]                                    diverts output to <filename> or to stdout.");
        System.err.println(
                "$weight {index:weight}                                  set index weights (unspecified weights are set to 1).");
        System.err.println("$mplex [<on>|<off>]                                     set/unset multiplex mode.");
        System.err.println(
                "$equalize <sample>                                      equalize scores using the given sample size.");
        System.err.println(
                "$score {<scorerClass>(<arg>,...)[:<weight>]}            order documents according to <scorerClass>.");
        System.err.println(
                "$expand {<expanderClass>(<arg>,...)}                    expand terms and prefixes according to <expanderClass>.");
        System.err.println("$quit                                                   quits.");
        return true;
    }

    try {
        command = Command.valueOf(part[0].toUpperCase());
    } catch (IllegalArgumentException e) {
        System.err.println("Invalid command \"" + part[0] + "\"; type $ for help.");
        return true;
    }

    switch (command) {
    case MODE:
        if (part.length >= 2) {
            try {
                final OutputType tempMode = OutputType.valueOf(part[1].toUpperCase());

                if (tempMode != OutputType.TREC && part.length > 2)
                    System.err.println("Extra arguments.");
                else if (tempMode == OutputType.TREC && part.length != 4)
                    System.err.println("Missing or extra arguments.");
                else {
                    displayMode = tempMode;
                    if (displayMode == OutputType.TREC) {
                        trecTopicNumber = Integer.parseInt(part[2]);
                        trecRunTag = part[3];
                    }
                }
            } catch (IllegalArgumentException e) {
                System.err.println("Unknown mode: " + part[1]);
            }
        } else
            System.err.println("Missing mode.");
        break;

    case LIMIT:
        int out = -1;
        if (part.length == 2) {
            try {
                out = Integer.parseInt(part[1]);
            } catch (NumberFormatException e) {
            }
            if (out >= 0)
                maxOutput = out;
        }
        if (out < 0)
            System.err.println("Missing or incorrect limit.");
        break;

    case SCORE:
        final Scorer[] scorer = new Scorer[part.length - 1];
        final double[] weight = new double[part.length - 1];
        for (i = 1; i < part.length; i++)
            try {
                weight[i - 1] = loadClassFromSpec(part[i], scorer, i - 1);
                if (weight[i - 1] < 0)
                    throw new IllegalArgumentException("Weights should be non-negative");
            } catch (Exception e) {
                System.err.print("Error while parsing specification: ");
                e.printStackTrace(System.err);
                break;
            }
        if (i == part.length)
            queryEngine.score(scorer, weight);
        break;

    case EXPAND:
        if (part.length > 2)
            System.err.println("Wrong argument(s) to command");
        else if (part.length == 1) {
            queryEngine.transformer(null);
        } else {
            QueryTransformer[] t = new QueryTransformer[1];
            try {
                loadClassFromSpec(part[1], t, 0);
                queryEngine.transformer(t[0]);
            } catch (Exception e) {
                System.err.print("Error while parsing specification: ");
                e.printStackTrace(System.err);
                break;
            }
        }
        break;

    case MPLEX:
        if (part.length != 2 || (part.length == 2 && !"on".equals(part[1]) && !"off".equals(part[1])))
            System.err.println("Wrong argument(s) to command");
        else {
            if (part.length > 1)
                queryEngine.multiplex = "on".equals(part[1]);
            System.err.println("Multiplex: " + part[1]);
        }
        break;

    case DIVERT:
        if (part.length > 2)
            System.err.println("Wrong argument(s) to command");
        else {
            if (outputDH != System.out)
                outputDH.close();
            outputPH.close();
            try {
                outputDH = part.length == 1 ? System.out
                        : new PrintStream(new FastBufferedOutputStream(
                                new FileOutputStream(part[1] + "-" + dhBatch++ + ".dh.txt")));
                outputPH = part.length == 1 ? System.out
                        : new PrintStream(new FastBufferedOutputStream(
                                new FileOutputStream(part[1] + "-" + phBatch++ + ".ph.txt")));
                outputName = part[1];
            } catch (FileNotFoundException e) {
                System.err.println("Cannot create file " + part[1]);
                outputDH = System.out;
                outputPH = System.out;
            }
        }
        break;

    case EQUALIZE:
        try {
            if (part.length != 2)
                throw new NumberFormatException("Illegal number of arguments");
            queryEngine.equalize(Integer.parseInt(part[1]));
            System.err.println("Equalization sample set to " + Integer.parseInt(part[1]));
        } catch (NumberFormatException e) {
            System.err.println(e.getMessage());
        }
        break;

    case QUIT:
        return false;
    }
    return true;
}

From source file:edu.nyu.tandon.tool.RawDocHits_deprecated.java

/**
 * Interpret the given command, changing the static variables.
 * See the help printing code for possible commands.
 *
 * @param line the command line.//from ww w .j a va  2 s . c o  m
 * @return false iff we should exit after this command.
 */
public boolean interpretCommand(final String line) {
    String[] part = line.substring(1).split("[ \t\n\r]+");

    final Command command;
    int i;

    if (part[0].length() == 0) {
        System.err.println("$                                                       prints this help.");
        System.err.println("$mode [time|short|long|snippet|trec <topicNo> <runTag>] chooses display mode.");
        System.err.println(
                "$select [<maxIntervals> <maxLength>] [all]              installs or removes an interval selector.");
        System.err.println(
                "$limit <max>                                            output at most <max> results per query.");
        System.err.println(
                "$divert [<filename>]                                    diverts output to <filename> or to stdout.");
        System.err.println(
                "$weight {index:weight}                                  set index weights (unspecified weights are set to 1).");
        System.err.println("$mplex [<on>|<off>]                                     set/unset multiplex mode.");
        System.err.println(
                "$equalize <sample>                                      equalize scores using the given sample size.");
        System.err.println(
                "$score {<scorerClass>(<arg>,...)[:<weight>]}            order documents according to <scorerClass>.");
        System.err.println(
                "$expand {<expanderClass>(<arg>,...)}                    expand terms and prefixes according to <expanderClass>.");
        System.err.println("$quit                                                   quits.");
        return true;
    }

    try {
        command = Command.valueOf(part[0].toUpperCase());
    } catch (IllegalArgumentException e) {
        System.err.println("Invalid command \"" + part[0] + "\"; type $ for help.");
        return true;
    }

    switch (command) {
    case MODE:
        if (part.length >= 2) {
            try {
                final OutputType tempMode = OutputType.valueOf(part[1].toUpperCase());

                if (tempMode != OutputType.TREC && part.length > 2)
                    System.err.println("Extra arguments.");
                else if (tempMode == OutputType.TREC && part.length != 4)
                    System.err.println("Missing or extra arguments.");
                else {
                    displayMode = tempMode;
                    if (displayMode == OutputType.TREC) {
                        trecTopicNumber = Integer.parseInt(part[2]);
                        trecRunTag = part[3];
                    }
                }
            } catch (IllegalArgumentException e) {
                System.err.println("Unknown mode: " + part[1]);
            }
        } else
            System.err.println("Missing mode.");
        break;

    case LIMIT:
        int out = -1;
        if (part.length == 2) {
            try {
                out = Integer.parseInt(part[1]);
            } catch (NumberFormatException e) {
            }
            if (out >= 0)
                maxOutput = out;
        }
        if (out < 0)
            System.err.println("Missing or incorrect limit.");
        break;

    case SELECT:
        int maxIntervals = -1, maxLength = -1;
        if (part.length == 1) {
            queryEngine.intervalSelector = null;
            System.err.println("Intervals have been disabled.");
        } else if (part.length == 2 && "all".equals(part[1])) {
            queryEngine.intervalSelector = new IntervalSelector(); // All intervals
            System.err.println("Interval selection has been disabled (will compute all intervals).");
        } else {
            if (part.length == 3) {
                try {
                    maxIntervals = Integer.parseInt(part[1]);
                    maxLength = Integer.parseInt(part[2]);
                    queryEngine.intervalSelector = new IntervalSelector(maxIntervals, maxLength);
                } catch (NumberFormatException e) {
                }
            }
            if (maxIntervals < 0 || maxLength < 0)
                System.err.println("Missing or incorrect selector parameters.");
        }
        break;

    case SCORE:
        final Scorer[] scorer = new Scorer[part.length - 1];
        final double[] weight = new double[part.length - 1];
        for (i = 1; i < part.length; i++)
            try {
                weight[i - 1] = loadClassFromSpec(part[i], scorer, i - 1);
                if (weight[i - 1] < 0)
                    throw new IllegalArgumentException("Weights should be non-negative");
            } catch (Exception e) {
                System.err.print("Error while parsing specification: ");
                e.printStackTrace(System.err);
                break;
            }
        if (i == part.length)
            queryEngine.score(scorer, weight);
        break;

    case EXPAND:
        if (part.length > 2)
            System.err.println("Wrong argument(s) to command");
        else if (part.length == 1) {
            queryEngine.transformer(null);
        } else {
            QueryTransformer[] t = new QueryTransformer[1];
            try {
                loadClassFromSpec(part[1], t, 0);
                queryEngine.transformer(t[0]);
            } catch (Exception e) {
                System.err.print("Error while parsing specification: ");
                e.printStackTrace(System.err);
                break;
            }
        }
        break;

    case MPLEX:
        if (part.length != 2 || (part.length == 2 && !"on".equals(part[1]) && !"off".equals(part[1])))
            System.err.println("Wrong argument(s) to command");
        else {
            if (part.length > 1)
                queryEngine.multiplex = "on".equals(part[1]);
            System.err.println("Multiplex: " + part[1]);
        }
        break;

    case DIVERT:
        if (part.length > 2)
            System.err.println("Wrong argument(s) to command");
        else {
            if (output != System.out)
                output.close();
            try {
                output = part.length == 1 ? System.out
                        : new PrintStream(new FastBufferedOutputStream(
                                new FileOutputStream(part[1] + "-" + batch++ + ".txt")));
                outputName = part[1];
            } catch (FileNotFoundException e) {
                System.err.println("Cannot create file " + part[1]);
                output = System.out;
            }
        }
        break;

    case EQUALIZE:
        try {
            if (part.length != 2)
                throw new NumberFormatException("Illegal number of arguments");
            queryEngine.equalize(Integer.parseInt(part[1]));
            System.err.println("Equalization sample set to " + Integer.parseInt(part[1]));
        } catch (NumberFormatException e) {
            System.err.println(e.getMessage());
        }
        break;

    case QUIT:
        return false;
    }
    return true;
}

From source file:edu.nyu.tandon.query.Query.java

/**
 * Interpret the given command, changing the static variables.
 * See the help printing code for possible commands.
 *
 * @param line the command line./*from   ww w .ja  v a  2 s.com*/
 * @return false iff we should exit after this command.
 */
public boolean interpretCommand(final String line) {
    String[] part = line.substring(1).split("[ \t\n\r]+");

    final Command command;
    int i;

    if (part[0].length() == 0) {
        System.err.println("$                                                       prints this help.");
        System.err.println("$mode [time|short|long|snippet|trec <topicNo> <runTag>] chooses display mode.");
        System.err.println(
                "$select [<maxIntervals> <maxLength>] [all]              installs or removes an interval selector.");
        System.err.println(
                "$limit <max>                                            output at most <max> results per query.");
        System.err.println(
                "$divert [<filename>]                                    diverts output to <filename> or to stdout.");
        System.err.println(
                "$weight {index:weight}                                  set index weights (unspecified weights are set to 1).");
        System.err.println("$mplex [<on>|<off>]                                     set/unset multiplex mode.");
        System.err.println(
                "$equalize <sample>                                      equalize scores using the given sample size.");
        System.err.println(
                "$score {<scorerClass>(<arg>,...)[:<weight>]}            order documents according to <scorerClass>.");
        System.err.println(
                "$expand {<expanderClass>(<arg>,...)}                    expand terms and prefixes according to <expanderClass>.");
        System.err.println("$quit                                                   quits.");
        return true;
    }

    try {
        command = Command.valueOf(part[0].toUpperCase());
    } catch (IllegalArgumentException e) {
        System.err.println("Invalid command \"" + part[0] + "\"; type $ for help.");
        return true;
    }

    switch (command) {
    case MODE:
        if (part.length >= 2) {
            try {
                final OutputType tempMode = OutputType.valueOf(part[1].toUpperCase());

                if (tempMode != OutputType.TREC && part.length > 2)
                    System.err.println("Extra arguments.");
                else if (tempMode == OutputType.TREC && part.length != 4)
                    System.err.println("Missing or extra arguments.");
                else {
                    displayMode = tempMode;
                    if (displayMode == OutputType.TREC) {
                        trecTopicNumber = Integer.parseInt(part[2]);
                        trecRunTag = part[3];
                    }
                }
            } catch (IllegalArgumentException e) {
                System.err.println("Unknown mode: " + part[1]);
            }
        } else
            System.err.println("Missing mode.");
        break;

    case LIMIT:
        int out = -1;
        if (part.length == 2) {
            try {
                out = Integer.parseInt(part[1]);
            } catch (NumberFormatException e) {
            }
            if (out >= 0)
                maxOutput = out;
        }
        if (out < 0)
            System.err.println("Missing or incorrect limit.");
        break;

    case SELECT:
        int maxIntervals = -1, maxLength = -1;
        if (part.length == 1) {
            queryEngine.intervalSelector = null;
            System.err.println("Intervals have been disabled.");
        } else if (part.length == 2 && "all".equals(part[1])) {
            queryEngine.intervalSelector = new IntervalSelector(); // All intervals
            System.err.println("Interval selection has been disabled (will compute all intervals).");
        } else {
            if (part.length == 3) {
                try {
                    maxIntervals = Integer.parseInt(part[1]);
                    maxLength = Integer.parseInt(part[2]);
                    queryEngine.intervalSelector = new IntervalSelector(maxIntervals, maxLength);
                } catch (NumberFormatException e) {
                }
            }
            if (maxIntervals < 0 || maxLength < 0)
                System.err.println("Missing or incorrect selector parameters.");
        }
        break;

    case SCORE:
        final Scorer[] scorer = new Scorer[part.length - 1];
        final double[] weight = new double[part.length - 1];
        for (i = 1; i < part.length; i++)
            try {
                weight[i - 1] = loadClassFromSpec(part[i], scorer, i - 1);
                if (weight[i - 1] < 0)
                    throw new IllegalArgumentException("Weights should be non-negative");
            } catch (Exception e) {
                System.err.print("Error while parsing specification: ");
                e.printStackTrace(System.err);
                break;
            }
        if (i == part.length)
            queryEngine.score(scorer, weight);
        break;

    case EXPAND:
        if (part.length > 2)
            System.err.println("Wrong argument(s) to command");
        else if (part.length == 1) {
            queryEngine.transformer(null);
        } else {
            QueryTransformer[] t = new QueryTransformer[1];
            try {
                loadClassFromSpec(part[1], t, 0);
                queryEngine.transformer(t[0]);
            } catch (Exception e) {
                System.err.print("Error while parsing specification: ");
                e.printStackTrace(System.err);
                break;
            }
        }
        break;

    case MPLEX:
        if (part.length != 2 || (part.length == 2 && !"on".equals(part[1]) && !"off".equals(part[1])))
            System.err.println("Wrong argument(s) to command");
        else {
            if (part.length > 1)
                queryEngine.multiplex = "on".equals(part[1]);
            System.err.println("Multiplex: " + part[1]);
        }
        break;

    case DIVERT:
        if (part.length > 2)
            System.err.println("Wrong argument(s) to command");
        else {
            if (output != System.out)
                output.close();
            try {
                output = part.length == 1 ? System.out
                        : new PrintStream(new FastBufferedOutputStream(new FileOutputStream(part[1])));
            } catch (FileNotFoundException e) {
                System.err.println("Cannot create file " + part[1]);
                output = System.out;
            }
        }
        break;

    case WEIGHT:
        final Reference2DoubleOpenHashMap<Index> newIndex2Weight = new Reference2DoubleOpenHashMap<Index>();
        for (i = 1; i < part.length; i++) {
            final int pos = part[i].indexOf(':');
            if (pos < 0) {
                System.err.println("Missing colon: " + part[i]);
                break;
            } else if (!queryEngine.indexMap.containsKey(part[i].substring(0, pos))) {
                System.err.println("Unknown index: " + part[i].substring(0, pos));
                break;
            }
            try {
                double newWeight = Double.parseDouble(part[i].substring(pos + 1));
                newIndex2Weight.put(queryEngine.indexMap.get(part[i].substring(0, pos)), newWeight);
            } catch (NumberFormatException e) {
                System.err.println("Wrong weight specification: " + part[i].substring(pos + 1));
                break;
            }
        }
        if (i == part.length) {
            if (i > 1)
                queryEngine.setWeights(newIndex2Weight);
            for (String key : queryEngine.indexMap.keySet())
                System.err.print(key + ":" + newIndex2Weight.getDouble(queryEngine.indexMap.get(key)) + " ");
            System.err.println();
        }
        break;

    case EQUALIZE:
        try {
            if (part.length != 2)
                throw new NumberFormatException("Illegal number of arguments");
            queryEngine.equalize(Integer.parseInt(part[1]));
            System.err.println("Equalization sample set to " + Integer.parseInt(part[1]));
        } catch (NumberFormatException e) {
            System.err.println(e.getMessage());
        }
        break;

    case QUIT:
        return false;
    }

    return true;
}