List of usage examples for java.lang NumberFormatException NumberFormatException
public NumberFormatException()
NumberFormatException
with no detail message. From source file:com.qspin.qtaste.kernel.engine.TestEngine.java
public static void main(String[] args) { boolean executionResult = false; try {// ww w . j av a 2 s .c om // Log4j Configuration PropertyConfigurator.configure(StaticConfiguration.CONFIG_DIRECTORY + "/log4j.properties"); // log version information logger.info("QTaste kernel version: " + com.qspin.qtaste.kernel.Version.getInstance().getFullVersion()); logger.info("QTaste testAPI version: " + VersionControl.getInstance().getTestApiVersion("")); // handle optional config file name if ((args.length < 4) || (args.length > 10)) { showUsage(); } String testSuiteDir = null; String testbed = null; int numberLoops = 1; boolean loopsInHours = false; int i = 0; while (i < args.length) { if (args[i].equals("-testsuite") && (i + 1 < args.length)) { logger.info("Using " + args[i + 1] + " as test suite directory"); testSuiteDir = args[i + 1]; i += 2; } else if (args[i].equals("-testbed") && (i + 1 < args.length)) { logger.info("Using " + args[i + 1] + " as testbed configuration file"); testbed = args[i + 1]; i += 2; } else if (args[i].equals("-engine") && (i + 1 < args.length)) { logger.info("Using " + args[i + 1] + " as engine configuration file"); TestEngineConfiguration.setConfigFile(args[i + 1]); i += 2; } else if (args[i].equals("-loop")) { String message = "Running test suite in loop"; numberLoops = -1; if ((i + 1 < args.length)) { // more arguments, check if next argument is a loop argument if (args[i + 1].startsWith("-")) { i++; } else { String countOrHoursStr; if (args[i + 1].endsWith("h")) { loopsInHours = true; countOrHoursStr = args[i + 1].substring(0, args[i + 1].length() - 1); } else { loopsInHours = false; countOrHoursStr = args[i + 1]; } try { numberLoops = Integer.parseInt(countOrHoursStr); if (numberLoops <= 0) { throw new NumberFormatException(); } message += (loopsInHours ? " during " : " ") + numberLoops + " " + (loopsInHours ? "hour" : "time") + (numberLoops > 1 ? "s" : ""); i += 2; } catch (NumberFormatException e) { showUsage(); } } } else { // no more arguments i++; } logger.info(message); } else if (args[i].equals("-sutversion") && (i + 1 < args.length)) { logger.info("Using " + args[i + 1] + " as sutversion"); TestBedConfiguration.setSUTVersion(args[i + 1]); i += 2; } else { showUsage(); } } if (testSuiteDir == null || testbed == null) { showUsage(); } TestBedConfiguration.setConfigFile(testbed); // start the log4j server Log4jServer.getInstance().start(); // initialize Python interpreter Properties properties = new Properties(); properties.setProperty("python.home", StaticConfiguration.JYTHON_HOME); properties.setProperty("python.path", StaticConfiguration.JYTHON_LIB); PythonInterpreter.initialize(System.getProperties(), properties, new String[] { "" }); TestSuite testSuite = DirectoryTestSuite.createDirectoryTestSuite(testSuiteDir); testSuite.setExecutionLoops(numberLoops, loopsInHours); executionResult = execute(testSuite); } finally { shutdown(); } System.exit(executionResult ? 0 : 1); }
From source file:netplot.GenericPlotPanel.java
public void setAttribute(String name, String value) throws NetPlotException { if (name == null || value == null || name.length() == 0) { throw new NetPlotException("setAttribute name/value invalid (" + name + "/" + value); }/*from ww w . ja va2 s . c om*/ if (name.equals(KeyWords.PLOT_TITLE)) { plotTitle = value; } else if (name.equals(KeyWords.PLOT_NAME)) { plotName = value; } else if (name.equals(KeyWords.X_AXIS_NAME)) { xAxisName = value; } else if (name.equals(KeyWords.Y_AXIS_NAME)) { yAxisName = value; } else if (name.equals(KeyWords.ENABLE_LINES)) { if (value.equals("true")) { linesEnabled = true; } else if (value.equals("false")) { linesEnabled = false; } else { throw new NetPlotException( value + " is an invalid value for " + KeyWords.ENABLE_LINES + ", must be true or false"); } } else if (name.equals(KeyWords.ENABLE_SHAPES)) { if (value.equals("true")) { shapesEnabled = true; } else if (value.equals("false")) { shapesEnabled = false; } else { throw new NetPlotException( value + " is an invalid value for " + KeyWords.ENABLE_SHAPES + ", must be true or false"); } } else if (name.equals(KeyWords.ENABLE_AUTOSCALE)) { if (value.equals("true")) { autoScaleEnabled = true; } else if (value.equals("false")) { autoScaleEnabled = false; } else { throw new NetPlotException(value + " is an invalid value for " + KeyWords.ENABLE_AUTOSCALE + ", must be true or false"); } } else if (name.equals(KeyWords.MIN_SCALE_VALUE)) { try { minScaleValue = Double.parseDouble(value); } catch (NumberFormatException e) { throw new NetPlotException(value + " is an invalid value for " + KeyWords.MIN_SCALE_VALUE + ", must be a double value"); } } else if (name.equals(KeyWords.MAX_SCALE_VALUE)) { try { maxScaleValue = Double.parseDouble(value); } catch (NumberFormatException e) { throw new NetPlotException(value + " is an invalid value for " + KeyWords.MAX_SCALE_VALUE + ", must be a double value"); } } else if (name.equals(KeyWords.MAX_AGE_SECONDS)) { try { maxAgeSeconds = Integer.parseInt(value); } catch (NumberFormatException e) { throw new NetPlotException(value + " is an invalid value for " + KeyWords.MAX_AGE_SECONDS + ", must be a integer value"); } } else if (name.equals(KeyWords.ENABLE_LOG_Y_AXIS)) { if (value.equals("true")) { logYAxis = true; } else if (value.equals("false")) { logYAxis = false; } else { throw new NetPlotException(value + " is an invalid value for " + KeyWords.ENABLE_LOG_Y_AXIS + ", must be true or false"); } } else if (name.equals(KeyWords.ENABLE_ZERO_ON_X_SCALE)) { if (value.equals("true")) { zeroOnXScale = true; } else if (value.equals("false")) { zeroOnXScale = false; } else { throw new NetPlotException(value + " is an invalid value for " + KeyWords.ENABLE_ZERO_ON_X_SCALE + ", must be true or false"); } } else if (name.equals(KeyWords.ENABLE_ZERO_ON_Y_SCALE)) { if (value.equals("true")) { zeroOnYScale = true; } else if (value.equals("false")) { zeroOnYScale = false; } else { throw new NetPlotException(value + " is an invalid value for " + KeyWords.ENABLE_ZERO_ON_Y_SCALE + ", must be true or false"); } } else if (name.equals(KeyWords.ENABLE_LEGEND)) { if (value.equals("true")) { enableLegend = true; } else if (value.equals("false")) { enableLegend = false; } else { throw new NetPlotException( value + " is an invalid value for " + KeyWords.ENABLE_LEGEND + ", must be true or false"); } } else if (name.equals(KeyWords.TICK_COUNT)) { try { yAxisTickCount = Integer.parseInt(value); } catch (NumberFormatException e) { throw new NetPlotException( value + " is an invalid value for " + KeyWords.TICK_COUNT + ", must be a integer value"); } } else if (name.equals(KeyWords.LINE_WIDTH)) { try { lineWidth = Integer.parseInt(value); if (lineWidth < 1) { throw new NumberFormatException(); } } catch (NumberFormatException e) { throw new NetPlotException(value + " is an invalid value for " + KeyWords.LINE_WIDTH + ", must be a int value in pixels"); } } else { throw new NetPlotException(name + " is an unknown attribute (value=" + value); } }
From source file:org.broad.igv.gwas.GWASParser.java
/** * Parse data from the given text line to {@code GWASData} instance provided * @param nextLine/*w w w. j a v a 2s . c o m*/ * @param lineNumber * @return Data container, with relevant info * @throws ParserException If there is an error parsing the line * */ private GWASEntry parseLine(String nextLine, long lineNumber) { String[] tokens = Globals.singleTabMultiSpacePattern.split(nextLine); if (tokens.length > 1) { //String chr = ParsingUtils.convertChrString(tokens[chrCol].trim()); String chr = genome.getChromosomeAlias(tokens[this.columns.chrCol].trim()); int start; try { start = Integer.parseInt(tokens[this.columns.locationCol].trim()); } catch (NumberFormatException e) { throw new ParserException("Column " + this.columns.locationCol + " must be a numeric value.", lineNumber, nextLine); } // Check if the p-value is NA if (!tokens[this.columns.pCol].trim().equalsIgnoreCase("NA")) { double p; try { p = Double.parseDouble(tokens[this.columns.pCol]); if (p <= 0) { throw new NumberFormatException(); } // Transform to -log10 p = -log10(p); } catch (NumberFormatException e) { throw new ParserException("Column " + this.columns.pCol + " must be a positive numeric value. Found " + tokens[this.columns.pCol], lineNumber, nextLine); } return new GWASEntry(chr, start, p, nextLine); } } return null; }
From source file:edu.buffalo.fusim.Fusim.java
public void run(String[] args) throws IOException, InterruptedException { buildOptions();/* w w w. j a va 2 s. c o m*/ CommandLineParser clParser = new PosixParser(); CommandLine cmd = null; try { cmd = clParser.parse(options, args); } catch (ParseException e) { printHelpAndExit(options, e.getMessage()); } if (cmd.hasOption("v")) { printVersionAndExit(); } if (cmd.hasOption("h") || cmd.getOptions().length == 0) { printHelpAndExit(options); } if (cmd.hasOption("z")) { if (!cmd.hasOption("i")) { printHelpAndExit(options, "Please specify a path to a GTF/GFF file for conversion with option -i"); } if (!cmd.hasOption("o")) { printHelpAndExit(options, "Please specify an output filename with option -O"); } File outFile = new File(cmd.getOptionValue("o")); File gtfFile = new File(cmd.getOptionValue("i")); if (!gtfFile.canRead()) { printHelpAndExit(options, "Can't read input GTF file"); } GTF2RefFlat gtf2Flat = new GTF2RefFlat(); gtf2Flat.convert(gtfFile, outFile); System.exit(0); } if (!cmd.hasOption("g")) { printHelpAndExit(options, "Please specify a path to a gene model file with option -g"); } File geneModelFile = new File(cmd.getOptionValue("g")); if (!geneModelFile.canRead()) { printHelpAndExit(options, "Can't read Gene Model file"); } PrintWriter textOutput = null; if (cmd.hasOption("t")) { if ("-".equals(cmd.getOptionValue("t"))) { textOutput = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8")); } else { textOutput = new PrintWriter( new OutputStreamWriter(new FileOutputStream(cmd.getOptionValue("t")), "UTF-8")); } } PrintWriter fastaOutput = null; if (cmd.hasOption("f")) { if ("-".equals(cmd.getOptionValue("f"))) { fastaOutput = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8")); } else { fastaOutput = new PrintWriter( new OutputStreamWriter(new FileOutputStream(cmd.getOptionValue("f")), "UTF-8")); } } // Default to TXT output if (fastaOutput == null && textOutput == null) { textOutput = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8")); } if (cmd.hasOption("f") && !cmd.hasOption("r")) { printHelpAndExit(options, "You must provide an indexed (.fai) genome reference file for FASTA output using option \"-r\"."); } File referenceFile = null; if (cmd.hasOption("r")) { referenceFile = new File(cmd.getOptionValue("r")); } if (cmd.hasOption("f") && !referenceFile.canRead()) { printHelpAndExit(options, "Please provide a valid reference file in fasta format"); } if (cmd.hasOption("f")) { File referenceIndexFile = new File(referenceFile.getAbsolutePath() + ".fai"); if (!referenceIndexFile.canRead()) { fatalError("Missing index file. Please index your fasta file with: samtools faidx my_genome.fa"); } } int nFusions = 0; if (cmd.hasOption("n")) { try { nFusions = Integer.parseInt(cmd.getOptionValue("n")); } catch (NumberFormatException e) { printHelpAndExit(options, "Number of fusions (-n) must be a number"); } } int nReadThrough = 0; if (cmd.hasOption("x")) { try { nReadThrough = Integer.parseInt(cmd.getOptionValue("x")); } catch (NumberFormatException e) { printHelpAndExit(options, "Number of read through fusion genes (-x) must be a number"); } } int nTriFusion = 0; if (cmd.hasOption("j")) { try { nTriFusion = Integer.parseInt(cmd.getOptionValue("j")); } catch (NumberFormatException e) { printHelpAndExit(options, "Number of tri-fusions (-j) must be a number"); } } int nIntraChromFusion = 0; if (cmd.hasOption("y")) { try { nIntraChromFusion = Integer.parseInt(cmd.getOptionValue("y")); } catch (NumberFormatException e) { printHelpAndExit(options, "Number of intra-chromosome fusions (-y) must be a number"); } } int nSelfFusion = 0; if (cmd.hasOption("s")) { try { nSelfFusion = Integer.parseInt(cmd.getOptionValue("s")); } catch (NumberFormatException e) { printHelpAndExit(options, "Number of self-fusions (-s) must be a number"); } } int foreignInsertionLen = 0; if (cmd.hasOption("u")) { try { foreignInsertionLen = Integer.parseInt(cmd.getOptionValue("u")); } catch (NumberFormatException e) { printHelpAndExit(options, "Foreign insertion length (-u) must be a number"); } } int nThreads = Runtime.getRuntime().availableProcessors(); if (cmd.hasOption("p")) { try { nThreads = Integer.parseInt(cmd.getOptionValue("p")); } catch (NumberFormatException e) { printHelpAndExit(options, "Number of threads to spawn (-p) must be a number"); } } double rpkmCutoff = 0.2; if (cmd.hasOption("k")) { try { rpkmCutoff = Double.parseDouble(cmd.getOptionValue("k")); if (rpkmCutoff < 0 || rpkmCutoff > 1) throw new NumberFormatException(); } catch (NumberFormatException e) { printHelpAndExit(options, "RPKM cutoff (-k) must be 0 < cutoff < 1"); } } double foreignInsertionPct = 0.0; if (cmd.hasOption("w")) { try { foreignInsertionPct = Double.parseDouble(cmd.getOptionValue("w")); if (foreignInsertionPct < 0 || foreignInsertionPct > 1) throw new NumberFormatException(); } catch (NumberFormatException e) { printHelpAndExit(options, "Foreign insertion percent (-w) must be 0 < x < 1"); } } GeneSelectionMethod geneSelectioMethod = GeneSelectionMethod.UNIFORM; if (cmd.hasOption("m")) { GeneSelectionMethod sm = GeneSelectionMethod.fromString(cmd.getOptionValue("m")); if (sm == null) { printHelpAndExit(options, "Invalid gene selection method: " + cmd.getOptionValue("m")); } geneSelectioMethod = sm; } Map<String, Boolean> limit = null; if (cmd.hasOption("l")) { limit = new HashMap<String, Boolean>(); String[] limits = cmd.getOptionValue("l").split(","); if (limits.length < 1) { printHelpAndExit(options, "Must provide a limit of at least one genes (ex. gene1,gene2,..): " + cmd.getOptionValue("l")); } for (int i = 0; i < limits.length; i++) { limit.put(limits[i], true); } } List<String[]> filters = new ArrayList<String[]>(); for (String filterOption : new String[] { "1", "2", "3" }) { if (cmd.hasOption(filterOption)) { filters.add(cmd.getOptionValue(filterOption).split(",")); } else { filters.add(null); } } File bamFile = null; if (cmd.hasOption("b")) { bamFile = new File(cmd.getOptionValue("b")); if (!bamFile.canRead()) { printHelpAndExit(options, "Please provide a valid BAM file"); } } logger.info("========================================================================"); logger.info("Running Fusim with the following settings:"); logger.info("========================================================================"); logger.info("Reference Gene Model: " + geneModelFile.getAbsolutePath()); if (cmd.hasOption("t")) { logger.info( "Text Output: " + ("-".equals(cmd.getOptionValue("t")) ? "<stdout>" : cmd.getOptionValue("t"))); } if (cmd.hasOption("f")) { logger.info("Fasta Output: " + ("-".equals(cmd.getOptionValue("f")) ? "<stdout>" : cmd.getOptionValue("f"))); } if (!cmd.hasOption("f") && !cmd.hasOption("t")) { logger.info("Text Output: <stdout>"); } logger.info(""); logger.info("------------------"); logger.info("Gene Selection"); logger.info("------------------"); if (cmd.hasOption("b")) { logger.info("Mode: background reads"); logger.info("BAM file: " + bamFile.getAbsolutePath()); logger.info("RPKM cutoff: " + rpkmCutoff); logger.info("Number of threads: " + nThreads); logger.info("Gene selection method: " + geneSelectioMethod.toString()); } else { logger.info("Mode: gene model"); } logger.info(""); logger.info("------------------"); logger.info("Type of fusions"); logger.info("------------------"); logger.info("Hybrid: " + nFusions); logger.info("Self: " + nSelfFusion); logger.info("Complex: " + nTriFusion); logger.info("Intra-chromosome: " + nIntraChromFusion); logger.info("Read through: " + nReadThrough); logger.info(""); logger.info("------------------"); logger.info("Fusion options"); logger.info("------------------"); logger.info("CDS only: " + (cmd.hasOption("c") ? "yes" : "no")); logger.info("Auto-correct orientation: " + (cmd.hasOption("a") ? "yes" : "no")); logger.info("Allow fusions outside of ORF: " + (cmd.hasOption("d") ? "yes" : "no")); logger.info("Force fusion breaks on exon boundries: " + (cmd.hasOption("e") ? "yes" : "no")); if (cmd.hasOption("u")) { logger.info("Foreign insertion max length: " + foreignInsertionLen); logger.info("Foreign insertion percent: " + foreignInsertionPct); } logger.info("========================================================================"); GeneModelParser parser = new UCSCRefFlatParser(cmd.hasOption("e"), cmd.hasOption("c"), limit); GeneSelector selector = null; FusionGenerator fg = null; if (cmd.hasOption("b")) { selector = new BackgroundSelector(bamFile, rpkmCutoff, nThreads); fg = new BackgroundGenerator(); } else { selector = new StaticSelector(); fg = new RandomGenerator(); } selector.setGeneModelFile(geneModelFile); selector.setGeneModelParser(parser); fg.setGeneSelector(selector); fg.setGeneSelectionMethod(geneSelectioMethod); fg.setFilters(filters); List<FusionGene> fusions = new ArrayList<FusionGene>(); if (nFusions > 0) { fusions.addAll(fg.generate(nFusions, 2)); } // Generate any read through fusion genes if (nReadThrough > 0) { logger.info("Generating read through genes..."); ReadThroughGenerator rt = new ReadThroughGenerator(); rt.setGeneSelector(selector); rt.setGeneSelectionMethod(geneSelectioMethod); List<FusionGene> rtFusions = rt.generate(nReadThrough, 2); for (FusionGene g : rtFusions) { g.setFusionType(FusionType.READ_THROUGH); } fusions.addAll(rtFusions); } // Generate any tri-fusions if (nTriFusion > 0) { logger.info("Generating tri-fusion genes..."); List<FusionGene> tfusions = fg.generate(nTriFusion, 3); for (FusionGene g : tfusions) { g.setFusionType(FusionType.TRI_FUSION); } fusions.addAll(tfusions); } // Generate any intra chromosome fusions if (nIntraChromFusion > 0) { logger.info("Generating intra-chromosome fusions..."); IntraChromGenerator ig = new IntraChromGenerator(); ig.setGeneSelector(selector); ig.setGeneSelectionMethod(geneSelectioMethod); List<FusionGene> ifusions = ig.generate(nIntraChromFusion, 2); for (FusionGene g : ifusions) { g.setFusionType(FusionType.INTRA_CHROMOSOME); } fusions.addAll(ifusions); } // Generate any self-fusions if (nSelfFusion > 0) { logger.info("Generating self-fusion genes..."); List<FusionGene> sfusions = fg.generate(nSelfFusion, 1); for (FusionGene g : sfusions) { g.setFusionType(FusionType.SELF_FUSION); } fusions.addAll(sfusions); } if (fusions.size() == 0) { fatalError( "No fusions to simulate! Check to be sure you have -j,-n,-s,-x,-y specified and your filters are correct."); } if (textOutput != null) { textOutput.println(StringUtils.join(FusionGene.getHeader(), "\t")); } int foreignInsertionCutoff = (int) (foreignInsertionPct * fusions.size()); Random rgen = new Random(); for (int g = 0; g < fusions.size(); g++) { FusionGene f = fusions.get(g); //out.println(f); List<int[]> breaks = new ArrayList<int[]>(); // First half of gene 1 breaks.add(f.getGene(0).generateExonBreak(true, cmd.hasOption("c"))); if (f.size() == 2) { // Second half of gene2 breaks.add(f.getGene(1).generateExonBreak(false, cmd.hasOption("c"))); } else if (f.size() == 3) { // Second half of gene2 breaks.add(f.getGene(1).generateExonBreak(false, cmd.hasOption("c"))); // Second half of gene3 breaks.add(f.getGene(2).generateExonBreak(false, cmd.hasOption("c"))); } // Keep ORF (don't allow out of frame) and allow splitting of exons if (!cmd.hasOption("d") && !cmd.hasOption("e")) { // Split last exon in half and ensure within ORF for (int i = 0; i < breaks.size(); i++) { int[] exons = breaks.get(i); int[] lastExon = f.getGene(i).getExons(cmd.hasOption("c")).get(exons[exons.length - 1]); int randIndex = rgen.nextInt(lastExon[1] - lastExon[0]); while (randIndex % 3 != 0) { randIndex--; } f.getGene(i).getExons(cmd.hasOption("c")).get(exons[exons.length - 1])[1] -= randIndex; } } else if (cmd.hasOption("e") && !cmd.hasOption("d")) { breaks.clear(); // Keep ORF (don't allow out of frame) and don't allow splitting of exons (keep exon boundries) // Break genes on exons boundries breaks.add(f.getGene(0).generateExonBoundryBreak(cmd.hasOption("c"))); if (f.size() == 2) { breaks.add(f.getGene(1).generateExonBoundryBreak(cmd.hasOption("c"))); } else if (f.size() == 3) { breaks.add(f.getGene(2).generateExonBoundryBreak(cmd.hasOption("c"))); breaks.add(f.getGene(3).generateExonBoundryBreak(cmd.hasOption("c"))); } } // Set options for output if (cmd.hasOption("a")) { f.addOption(FusionOption.AUTO_CORRECT_ORIENTATION); } if (cmd.hasOption("c")) { f.addOption(FusionOption.CDS_ONLY); } if (cmd.hasOption("d")) { f.addOption(FusionOption.OUT_OF_FRAME); } else { f.addOption(FusionOption.SYMMETRICAL_EXONS); } if (cmd.hasOption("e")) { f.addOption(FusionOption.KEEP_EXON_BOUNDRY); } if (textOutput != null) { textOutput.print(f.outputText(breaks, cmd.hasOption("c"))); } if (fastaOutput != null) { if (foreignInsertionLen > 0 && foreignInsertionCutoff > 0 && g <= foreignInsertionCutoff) { f.addOption(FusionOption.FOREIGN_INSERTION); fastaOutput.println(f.outputFasta(breaks, referenceFile, cmd.hasOption("c"), cmd.hasOption("a"), foreignInsertionLen)); } else { fastaOutput .println(f.outputFasta(breaks, referenceFile, cmd.hasOption("c"), cmd.hasOption("a"))); } } } if (textOutput != null) textOutput.flush(); if (fastaOutput != null) fastaOutput.flush(); logger.info("Fusim run complete. Goodbye!"); }
From source file:eu.stratosphere.pact.common.io.DelimitedInputFormat.java
/** * Configures this input format by reading the path to the file from the configuration and the string that * defines the record delimiter.//w w w . ja va 2 s. c o m * * @param parameters The configuration object to read the parameters from. */ @Override public void configure(Configuration parameters) { super.configure(parameters); final String delimString = parameters.getString(RECORD_DELIMITER, AbstractConfigBuilder.NEWLINE_DELIMITER); if (delimString == null) { throw new IllegalArgumentException("The delimiter not be null."); } final String charsetName = parameters.getString(RECORD_DELIMITER_ENCODING, null); try { this.delimiter = charsetName == null ? delimString.getBytes() : delimString.getBytes(charsetName); } catch (UnsupportedEncodingException useex) { throw new IllegalArgumentException("The charset with the name '" + charsetName + "' is not supported on this TaskManager instance.", useex); } // set the number of samples this.numLineSamples = NUM_SAMPLES_UNDEFINED; final String samplesString = parameters.getString(NUM_STATISTICS_SAMPLES, null); if (samplesString != null) { try { this.numLineSamples = Integer.parseInt(samplesString); if (this.numLineSamples < 0) { throw new NumberFormatException(); } } catch (NumberFormatException nfex) { if (LOG.isWarnEnabled()) LOG.warn("Invalid value for number of samples to take: " + samplesString + ". Skipping sampling."); this.numLineSamples = 0; } } }
From source file:com.funambol.admin.settings.panels.EditRollingFileAppender.java
/** * Validates the inputs and throws an Exception in case of any invalid data. * * @throws IllegalArgumentException in case of invalid input *//*from w ww . j a v a2s . c o m*/ private void validateValues() throws IllegalArgumentException { String value = null; value = conversionPattern.getText(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException("'Conversion pattern' cannot be empty."); } value = fileNameValue.getText(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException("'File name' cannot be empty."); } value = fileSizeValue.getText(); try { int intValue = Integer.parseInt(value); if (intValue < 0 || intValue > MAX_FILE_SIZE) { throw new NumberFormatException(); } } catch (NumberFormatException ex) { String msg = MessageFormat.format(Bundle.getMessage(Bundle.ERROR_NUMERIC_INPUT), new String[] { Bundle.getMessage(Bundle.LABEL_MAX_FILE_SIZE), "0", String.valueOf(MAX_FILE_SIZE) }); throw new IllegalArgumentException(msg); } value = fileRotationCountValue.getText(); try { int intValue = Integer.parseInt(value); if (intValue < 0 || intValue > Integer.MAX_VALUE) { throw new NumberFormatException(); } } catch (NumberFormatException ex) { String msg = MessageFormat.format(Bundle.getMessage(Bundle.ERROR_NUMERIC_INPUT), new String[] { Bundle.getMessage(Bundle.LABEL_MAX_BACKUP_INDEX), "0", String.valueOf(Integer.MAX_VALUE) }); throw new IllegalArgumentException(msg); } }
From source file:com.wso2telco.workflow.subscription.SubscriptionApprovalImpl.java
public void updateDBSubOpApproval(Subscription subOpApprovalDBUpdateRequest) throws Exception { int appID = subOpApprovalDBUpdateRequest.getApplicationID(); int opID;// w w w . j av a 2 s . c o m String statusStr = subOpApprovalDBUpdateRequest.getStatus(); int operatorEndpointID = -1; String apiName = subOpApprovalDBUpdateRequest.getApiName(); try { dbservice = new WorkflowDbService(); opID = dbservice.getOperatorIdByName(subOpApprovalDBUpdateRequest.getOperatorName()); List<OperatorEndPointDTO> operatorEndpoints = dbservice.getOperatorEndpoints(); for (Iterator iterator = operatorEndpoints.iterator(); iterator.hasNext();) { OperatorEndPointDTO operatorendpoint = (OperatorEndPointDTO) iterator.next(); if (operatorendpoint.getOperatorid() == opID && operatorendpoint.getApi().equalsIgnoreCase(apiName)) { operatorEndpointID = operatorendpoint.getId(); break; } } if (operatorEndpointID > 0 && statusStr != null && statusStr.length() > 0) { dbservice.updateOperatorAppEndpointStatus(appID, operatorEndpointID, ApprovelStatus.valueOf(statusStr).getValue()); } } catch (NumberFormatException e) { log.error("ERROR: NumberFormatException. " + e); throw new NumberFormatException(); } catch (Exception e) { log.error("ERROR: Exception. " + e); throw new BusinessException(GenaralError.INTERNAL_SERVER_ERROR); } }
From source file:org.rdv.viz.dial.DialPanel.java
/** * Sets the range of the dial according to the range text fields. *///from w w w. j ava 2 s.c o m private void setRangeFromTextFields() { double lowerBound; double upperBound; try { lowerBound = Double.parseDouble(lowerBoundTextField.getText()); upperBound = Double.parseDouble(upperBoundTextField.getText()); if (lowerBound >= upperBound) { throw new NumberFormatException(); } } catch (NumberFormatException e) { lowerBoundTextField.setText(engineeringFormat.format(model.getRange().getLowerBound())); upperBoundTextField.setText(engineeringFormat.format(model.getRange().getUpperBound())); return; } model.setRange(new Range(lowerBound, upperBound)); }
From source file:com.atlassian.clover.CloverInstr.java
private boolean processArgs(String[] args) { cfg = new JavaInstrumentationConfig(); try {/*ww w . j a va 2 s. c o m*/ int i = 0; while (i < args.length) { if (args[i].equals("-i") || args[i].equals("--initstring")) { i++; cfg.setInitstring(args[i]); } else if (args[i].equals("-r") || args[i].equals("--relative")) { cfg.setRelative(true); } else if (args[i].equals("-s") || args[i].equals("--srcdir")) { i++; inDir = (new File(args[i])).getAbsoluteFile(); } else if (args[i].equals("-d") || args[i].equals("--destdir")) { i++; outDir = (new File(args[i])).getAbsoluteFile(); } else if (args[i].equals("-e") || args[i].equals("--encoding")) { i++; cfg.setEncoding(args[i]); } else if (args[i].equals("--recordTestResults")) { i++; cfg.setRecordTestResults(Boolean.valueOf(args[i]).booleanValue()); } else if (args[i].equals("-dc") || args[i].equals("--distributedCoverage")) { i++; cfg.setDistributedConfig(new DistributedConfig(args[i])); } else if (args[i].equalsIgnoreCase("--dontFullyQualifyJavaLang")) { cfg.setFullyQualifyJavaLang(false); } else if (args[i].equals("-p") || args[i].equals("--flushpolicy")) { i++; String policy = args[i]; try { cfg.setFlushPolicyFromString(policy); } catch (CloverException e) { usage(e.getMessage()); return false; } } else if (args[i].equals("-f") || args[i].equals("--flushinterval")) { i++; try { cfg.setFlushInterval(Integer.parseInt(args[i])); if (cfg.getFlushInterval() <= 0) { throw new NumberFormatException(); } } catch (NumberFormatException e) { usage("expecting a positive integer value for flush interval"); return false; } } else if (args[i].equals("-u") || args[i].equals("--useclass")) { i++; log.warn("the useclass parameter has been deprecated and will be ignored."); } else if (args[i].equals("--source")) { i++; cfg.setSourceLevel(args[i]); } else if (args[i].equals("--instrumentation")) { i++; String instr = args[i]; cfg.setInstrStrategy(instr); } else if (args[i].equals("--instrlevel")) { i++; String instr = args[i]; cfg.setInstrLevelStrategy(instr); } else if (args[i].equals("--instrlambda")) { try { i++; cfg.setInstrumentLambda(LambdaInstrumentation.valueOf(args[i].toUpperCase(Locale.ENGLISH))); } catch (IllegalArgumentException ex) { usage("Invalid value: " + args[i] + ". " + ex.getMessage()); return false; } } else if (args[i].equals("-v") || args[i].equals("--verbose")) { Logger.setVerbose(true); } else if (args[i].equals("-mc") || args[i].equals("--methodContext")) { // expected in the format: name=value, where value may have one or more '=' i++; try { cfg.addMethodContext(parseContextDef(args[i])); } catch (CloverException e) { usage("Could not parse custom method context definition: " + args[i] + ". " + e.getMessage()); return false; } } else if (args[i].equals("-sc") || args[i].equals("--statementContext")) { // expected in the format: name=value, where value may have one or more '=' i++; try { cfg.addStatementContext(parseContextDef(args[i])); } catch (CloverException e) { usage("Could not parse custom statement context definition: " + args[i] + ". " + e.getMessage()); return false; } } else if (args[i].endsWith(".java")) { srcFiles.add(args[i]); } i++; } if (cfg.getInitString() == null) { try { cfg.createDefaultInitStringDir(); } catch (CloverException e) { usage("No --initstring value supplied, and default location could not be created: " + e.getMessage()); return false; } } if (inDir == null && srcFiles.size() == 0) { usage("No source files specified"); return false; } else if (outDir == null) { usage("No Destination dir specified"); return false; } else if ((cfg.getFlushPolicy() == InstrumentationConfig.INTERVAL_FLUSHING || cfg.getFlushPolicy() == InstrumentationConfig.THREADED_FLUSHING) && cfg.getFlushInterval() == 0) { usage("When using either \"interval\" or \"threaded\" flushpolicy, a flushinterval must be specified."); return false; } else { if (inDir != null) { if (inDir.equals(outDir)) { usage("Srcdir and destdir cannot be the same."); return false; } // check to see that indir is not a parent of outdir File outParent = outDir.getParentFile(); while (outParent != null) { if (outParent.equals(inDir)) { usage("Cannot specify a destdir that is a nested dir of the srcdir."); return false; } outParent = outParent.getParentFile(); } if (cfg.getFlushPolicy() == InstrumentationConfig.DIRECTED_FLUSHING && cfg.getFlushInterval() != 0) { log.warn( "ignoring flushinterval since flushpolicy is directed. To specify interval flushing, use -p interval."); } } return true; } } catch (ArrayIndexOutOfBoundsException e) { usage("Missing a parameter."); } return false; }