List of usage examples for java.lang ArithmeticException getMessage
public String getMessage()
From source file:com.dotosoft.dot4command.config.xml.XmlConfigParserTestCase.java
@Test public void testExecute2d() throws Exception { try {/*from w ww. j a v a2 s. c om*/ catalog.getCommand("Execute2d").execute(context); } catch (ArithmeticException e) { assertEquals("Correct exception id", "2", e.getMessage()); } assertThat(context, hasLog("1/2")); }
From source file:com.dotosoft.dot4command.config.xml.XmlConfigParserTestCase.java
@Test public void testExecute4c() throws Exception { try {/* w ww. j a va 2s. c o m*/ catalog.getCommand("Execute4c").execute(context); } catch (ArithmeticException e) { assertEquals("Correct exception id", "3", e.getMessage()); } assertThat(context, hasLog("1/2/3/c/b/a")); }
From source file:com.dotosoft.dot4command.config.xml.XmlConfigParserTestCase.java
@Test public void testExecute4d() throws Exception { try {/*w w w . j a v a 2 s . c o m*/ catalog.getCommand("Execute4d").execute(context); } catch (ArithmeticException e) { assertEquals("Correct exception id", "2", e.getMessage()); } assertThat(context, hasLog("1/2/b/a")); }
From source file:org.rdv.ui.channel.LocalChannelDialog.java
/** * Handles an exception thrown when creating a local channel. An error dialog * will display with the nature of the error. * //from www . j a v a 2 s .c o m * @param e the exception */ private void handleLocalChannelException(Exception e) { String errorTitle = PROPERTY_REPO.getValue(FORMULA_ERROR_TITLE_KEY); String errorMessage = "<html><body><font size=+1><b>" + PROPERTY_REPO.getValue(FORMULA_ERROR_MESSAGE_KEY) + "</b></font><br><br>"; if (e instanceof ArithmeticException) { ArithmeticException ae = (ArithmeticException) e; String message = ae.getMessage(); if (message.contains(": ")) { message = message.substring(message.indexOf(": ") + 2); } errorMessage += formatter.format(PROPERTY_REPO.getValue(ARITHMETIC_ERROR_MESSAGE_KEY), message); } else if (e instanceof SyntaxError) { SyntaxError se = (SyntaxError) e; int row = se.getRowIndex() + 1; int column = se.getColumnIndex(); String line = se.getCurrentLine(); if (column > line.length()) column = line.length(); errorMessage += formatter.format(PROPERTY_REPO.getValue(SYNTAX_ERROR_MESSAGE_KEY), row, column) + ":<br><pre>" + line + "<br>"; for (int i = 0; i < column - 1; i++) { errorMessage += " "; } errorMessage += "^</pre>"; } else { errorMessage += e.getMessage(); } errorMessage += "</body></html>"; JOptionPane.showMessageDialog(this, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE); }
From source file:org.apache.james.queue.jms.JMSMailQueue.java
public long computeNextDeliveryTimestamp(long delay, TimeUnit unit) { if (delay > 0) { try {//from ww w . ja v a 2 s . c o m return ZonedDateTime.now().plus(delay, Temporals.chronoUnit(unit)).toInstant().toEpochMilli(); } catch (ArithmeticException e) { LOGGER.warn( "The {} was caused by conversation {}({}) followed by addition to current timestamp. Falling back to Long.MAX_VALUE.", e.getMessage(), delay, unit.name()); return Long.MAX_VALUE; } } return NO_DELAY; }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractProductsController.java
@RequestMapping(value = "/editplannedcharges", method = RequestMethod.GET) public String editPlannedCharges( @RequestParam(value = "serviceInstanceUUID", required = true) String serviceInstanceUUID, ModelMap map) {// w ww .j av a2s . c o m logger.debug("### editPlannedCharges method starting...(GET)"); ProductForm productForm = new ProductForm(); productForm.setCurrencyPresicion( Integer.parseInt(config.getValue(Names.com_citrix_cpbm_portal_appearance_currency_precision))); Revision futureRevision = channelService.getFutureRevision(null); productForm.setStartDate(futureRevision.getStartDate()); Map<Product, List<ProductCharge>> plannedCharges = new HashMap<Product, List<ProductCharge>>(); for (ProductRevision productRevision : channelService.getFutureChannelRevision(null, false) .getProductRevisions()) { // Ignore removed products in the future revision if (productRevision.getProduct().getRemoved() == null && (productRevision.getProduct().getServiceInstance() != null && productRevision.getProduct() .getServiceInstance().getUuid().equals(serviceInstanceUUID))) { plannedCharges.put(productRevision.getProduct(), productRevision.getProductCharges()); } } productForm.setCurrentProductChargesMap(plannedCharges); List<CurrencyValue> activeCurrencies = currencyValueService.listActiveCurrencies(); Set<Entry<Product, List<ProductCharge>>> entrySet = plannedCharges.entrySet(); for (Entry<Product, List<ProductCharge>> entry : entrySet) { try { // if current price exists then clone otherwise create new product charge object for each currency. if (entry.getValue() != null && entry.getValue().size() > 0) { productForm.updateProductChargesFormList(entry.getKey(), entry.getValue(), activeCurrencies, futureRevision, false); } else { productForm.updateProductChargesFormList(entry.getKey(), null, activeCurrencies, futureRevision, true); } } catch (ArithmeticException ae) { logger.error("ArithmeticException while editing the product charge, Possible Cause- " + "the currency precision level was reduced " + ae); throw new CurrencyPrecisionException(ae.getMessage(), ae); } } map.addAttribute("productForm", productForm); map.addAttribute("currencieslist", activeCurrencies); map.addAttribute("currencieslistsize", activeCurrencies.size()); logger.debug("### editPlannedCharges method ending...(GET)"); return "edit.planned.charges"; }
From source file:org.displaytag.tags.TableTag.java
/** * This sets the list of all of the data that will be displayed on the page via the table tag. This might include * just a subset of the total data in the list due to to paging being active, or the user asking us to just show a * subset, etc...//w w w.ja va 2 s . c o m */ protected void setupViewableData() { if (this.totalRecords != null && this.tableModel.isSortFullTable()) { throw new RuntimeException( "If you set the totalRecords property, you won't be able to sort by list, only by table"); } // If the user has changed the way our default behavior works, then we // need to look for it now, and resort // things if needed before we ask for the viewable part. (this is a bad // place for this, this should be // refactored and moved somewhere else). if (this.tableModel.isSortFullTable()) { // Sort the total list... this.tableModel.sortFullList(); } Object originalData = this.tableModel.getRowListFull(); // If they have asked for a subset of the list via the length // attribute, then only fetch those items out of the master list. List fullList = CollectionUtil.getListFromObject(originalData, this.offset, this.length); int pageOffset = this.offset; // If they have asked for just a page of the data, then use the // SmartListHelper to figure out what page they are after, etc... if (this.pagesize > 0) { // expression evaluation. StringBuffer fullTotalRecords = new StringBuffer(); Object totalRecordsFound = null; int totalRecordsParam = 0; try { // append scope if (StringUtils.isNotBlank(this.scope)) { fullTotalRecords.append(this.scope).append("Scope."); } // base bean name if (this.name != null) { fullTotalRecords.append(this.totalRecords); } // append property if (StringUtils.isNotBlank(this.property)) { fullTotalRecords.append('.').append(this.property); } // only evaluate if needed, else preserve original list if (this.totalRecords != null) { totalRecordsFound = this.evaluateExpression(fullTotalRecords.toString()); } if (totalRecordsFound != null && totalRecordsFound instanceof String) { totalRecordsParam = Integer.parseInt((String) totalRecordsFound); } } catch (ObjectLookupException ole) { if (log.isErrorEnabled()) { log.error(ole.getMessage()); } } catch (ArithmeticException ae) { if (log.isErrorEnabled()) { log.error(ae.getMessage()); } } this.listHelper = new SmartListHelper(fullList, fullList.size(), this.pagesize, this.properties, totalRecordsParam); this.listHelper.setCurrentPage(this.pageNumber); pageOffset = this.listHelper.getFirstIndexForCurrentPage(); fullList = this.listHelper.getListForCurrentPage(); } this.tableModel.setRowListPage(fullList); this.tableModel.setPageOffset(pageOffset); }
From source file:ffx.algorithms.RotamerOptimization.java
/** * Calculates the energy at the current state, with the option to throw * instead of catching exceptions in the energy calculation. * * @param resList List of residues in current energy term. * @param catchError If true, catch force field exceptions. * @return Energy of the current state./*w ww .ja v a 2 s . c o m*/ */ private double currentEnergy(List<Residue> resList, boolean catchError) { /*if (x == null) { int nVar = potential.getNumberOfVariables(); x = new double[nVar * 3]; } if (catchError) { try { potential.getCoordinates(x); return potential.energy(x); } catch (ArithmeticException ex) { logger.warning(ex.getMessage()); return 1e100; } } else { potential.getCoordinates(x); return potential.energy(x); }*/ List<Rotamer> rots = resList.stream().map(Residue::getRotamer).collect(Collectors.toList()); File energyDir = dirSupplier.apply(resList, rots); if (catchError) { try { return eFunction.applyAsDouble(energyDir); } catch (ArithmeticException ex) { logger.warning(ex.getMessage()); return 1e100; } } else { return eFunction.applyAsDouble(energyDir); } }
From source file:ffx.algorithms.RotamerOptimization.java
/** * For decomposing the energies of the original (0th) rotamers without * computing the entire energy matrix.//w ww .j ava 2 s . c om */ public void decomposeOriginalParallel() { allResiduesList = new ArrayList<>(); polymers = molecularAssembly.getChains(); for (Polymer polymer : polymers) { ArrayList<Residue> current = polymer.getResidues(); for (Residue residuej : current) { if (residuej != null) { if (residuej.getRotamers(library) != null) { allResiduesList.add(residuej); } else if (useForcedResidues && chain != null) { Polymer setChain = molecularAssembly.getChain(chain); if (setChain.equals(polymer) && checkIfForced(residuej)) { allResiduesList.add(residuej); } } else if (useForcedResidues && checkIfForced(residuej)) { allResiduesList.add(residuej); } } } } numResidues = allResiduesList.size(); allResiduesArray = allResiduesList.toArray(new Residue[numResidues]); Residue residues[] = residueList.toArray(new Residue[residueList.size()]); int nRes = residues.length; distanceMatrix(); double totalEnergy; double localBackboneEnergy = 0; double localSelfEnergy[] = new double[nRes]; double pairEnergy[][] = new double[nRes][nRes]; double triEnergy[][][] = new double[nRes][nRes][nRes]; double residueEnergy[][] = new double[3][nRes]; for (int i = 0; i < nRes; i++) { turnOnAtoms(residues[i]); } totalEnergy = currentEnergy(allResiduesList); logIfMaster(String.format(" AMOEBA: %16.5f", totalEnergy)); for (int i = 0; i < nRes; i++) { turnOffAtoms(residues[i]); } List<Residue> rList = new ArrayList<>(Collections.nCopies(4, null)); try { localBackboneEnergy = currentEnergy(rList, false); } catch (ArithmeticException ex) { logger.severe(String.format("FFX shutting down: error in calculation of backbone energy %s", ex.getMessage())); } logIfMaster(String.format(" Backbone: %16.5f", localBackboneEnergy)); decomposeOriginal = true; allocateEliminationMemory(allResiduesArray); rotamerEnergies(allResiduesArray); if (master) { for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; localSelfEnergy[i] = selfEnergy[i][0]; residueEnergy[0][i] = localSelfEnergy[i]; logger.info(String.format(" Self %s: %16.5f", ri, localSelfEnergy[i])); } for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; for (int j = i + 1; j < nRes; j++) { Residue rj = residues[j]; pairEnergy[i][j] = twoBodyEnergy[i][0][j][0]; logger.info(String.format(" Pair %s %s: %16.5f", ri, rj, pairEnergy[i][j])); double halfPair = pairEnergy[i][j] * 0.5; residueEnergy[1][i] += halfPair; residueEnergy[1][j] += halfPair; } } if (threeBodyTerm) { for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; for (int j = i + 1; j < nRes; j++) { Residue rj = residues[j]; for (int k = j + 1; k < nRes; k++) { Residue rk = residues[k]; double dist = trimerDistance(i, 0, j, 0, k, 0); triEnergy[i][j][k] = threeBodyEnergy[i][0][j][0][k][0]; double thirdTrimer = triEnergy[i][j][k] / 3.0; residueEnergy[2][i] += thirdTrimer; residueEnergy[2][j] += thirdTrimer; residueEnergy[2][k] += thirdTrimer; if (triEnergy[i][j][k] != 0.0) { logger.info( String.format(" Tri %s %s %s: %16.5f", ri, rj, rk, triEnergy[i][j][k])); } else if (dist == Double.MAX_VALUE) { logger.info(String.format( " Tri %s %s %s: set to 0.0 at NaN (very long distance)", ri, rj, rk)); triEnergy[i][j][k] = 0.0; } else if (dist > threeBodyCutoffDist) { logger.info(String.format(" Tri %s %s %s: set to 0.0 at %1.5f Angstroms", ri, rj, rk, dist)); triEnergy[i][j][k] = 0.0; } else { String m = String.format( " Zero trimer energy inside cutoff: %s %s %s at %1.5f Angstroms.", ri, rj, rk, dist); logger.warning(m); } } } } } for (int i = 0; i < nRes; i++) { turnOnAtoms(residues[i]); } decomposePrint(residues, totalEnergy, localBackboneEnergy, residueEnergy); } decomposeOriginal = false; }
From source file:ffx.algorithms.RotamerOptimization.java
/** * For decomposing the energies of the original (0th) rotamers without * computing the entire energy matrix.// w w w.j a v a 2 s .com */ public void decomposeOriginal() { allResiduesList = new ArrayList<>(); polymers = molecularAssembly.getChains(); for (Polymer polymer : polymers) { ArrayList<Residue> current = polymer.getResidues(); for (Residue residuej : current) { if (residuej != null) { if (residuej.getRotamers(library) != null) { allResiduesList.add(residuej); } else if (useForcedResidues && chain != null) { Polymer setChain = molecularAssembly.getChain(chain); if (setChain.equals(polymer) && checkIfForced(residuej)) { allResiduesList.add(residuej); } } else if (useForcedResidues && checkIfForced(residuej)) { allResiduesList.add(residuej); } } } } numResidues = allResiduesList.size(); allResiduesArray = allResiduesList.toArray(new Residue[numResidues]); Residue residues[] = residueList.toArray(new Residue[residueList.size()]); int nRes = residues.length; distanceMatrix(); double totalEnergy; double localBackboneEnergy = 0; double localSelfEnergy[] = new double[nRes]; double pairEnergy[][] = new double[nRes][nRes]; double triEnergy[][][] = new double[nRes][nRes][nRes]; double residueEnergy[][] = new double[3][nRes]; for (int i = 0; i < nRes; i++) { turnOnAtoms(residues[i]); } totalEnergy = currentEnergy(allResiduesList); for (int i = 0; i < nRes; i++) { turnOffAtoms(residues[i]); } // List to contain current residues. List<Residue> rList = new ArrayList<>(Collections.nCopies(4, null)); try { localBackboneEnergy = currentEnergy(rList); } catch (ArithmeticException ex) { logger.severe(String.format("FFX shutting down: error in calculation of backbone energy %s", ex.getMessage())); } for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; rList.set(0, ri); turnOnAtoms(ri); localSelfEnergy[i] = currentEnergy(rList) - localBackboneEnergy; logger.info(String.format(" Self %s: %16.5f", ri, localSelfEnergy[i])); residueEnergy[0][i] = localSelfEnergy[i]; turnOffAtoms(ri); } for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; rList.set(0, ri); turnOnAtoms(ri); for (int j = i + 1; j < nRes; j++) { Residue rj = residues[j]; rList.set(1, rj); turnOnAtoms(rj); pairEnergy[i][j] = currentEnergy(rList) - localSelfEnergy[i] - localSelfEnergy[j] - localBackboneEnergy; logger.info(String.format(" Pair %s %s: %16.5f", ri, rj, pairEnergy[i][j])); double halfPair = pairEnergy[i][j] * 0.5; residueEnergy[1][i] += halfPair; residueEnergy[1][j] += halfPair; turnOffAtoms(rj); } turnOffAtoms(ri); } for (int i = 0; i < nRes; i++) { Residue ri = residues[i]; rList.set(0, ri); turnOnAtoms(ri); for (int j = i + 1; j < nRes; j++) { Residue rj = residues[j]; rList.set(1, rj); turnOnAtoms(rj); for (int k = j + 1; k < nRes; k++) { Residue rk = residues[k]; rList.set(2, rk); double dist = trimerDistance(i, 0, j, 0, k, 0); if (dist < threeBodyCutoffDist) { turnOnAtoms(rk); triEnergy[i][j][k] = currentEnergy(rList) - localSelfEnergy[i] - localSelfEnergy[j] - localSelfEnergy[k] - pairEnergy[i][j] - pairEnergy[j][k] - pairEnergy[i][k] - localBackboneEnergy; logger.info(String.format(" Tri %s %s %s: %16.5f", ri, rj, rk, triEnergy[i][j][k])); double thirdTrimer = triEnergy[i][j][k] / 3.0; residueEnergy[2][i] += thirdTrimer; residueEnergy[2][j] += thirdTrimer; residueEnergy[2][k] += thirdTrimer; turnOffAtoms(rk); } else if (dist == Double.MAX_VALUE) { logger.info(String.format(" Tri %s %s %s: set to 0.0 at NaN (very long distance)", ri, rj, rk)); triEnergy[i][j][k] = 0.0; } else { logger.info(String.format(" Tri %s %s %s: set to 0.0 at %1.5f Angstroms", ri, rj, rk, dist)); triEnergy[i][j][k] = 0.0; } } turnOffAtoms(rj); } turnOffAtoms(ri); } for (int i = 0; i < nRes; i++) { turnOnAtoms(residues[i]); } decomposePrint(residues, totalEnergy, localBackboneEnergy, residueEnergy); }