List of usage examples for java.lang NumberFormatException getMessage
public String getMessage()
From source file:net.di2e.ecdr.querylanguage.basic.CDRKeywordQueryLanguage.java
protected GeospatialCriteria createGeospatialCriteria(String rad, String lat, String lon, String box, String geom, String polygon, String geoRelation, double defaultRadius) throws UnsupportedQueryException { GeospatialCriteria geoCriteria = null; if (StringUtils.isNotBlank(box)) { try {//from w ww .jav a2 s . c o m String[] bboxArray = box.split(" |,\\p{Space}?"); if (bboxArray.length != 3) { double minX = NumberUtils.createDouble(bboxArray[0]); double minY = NumberUtils.createDouble(bboxArray[1]); double maxX = NumberUtils.createDouble(bboxArray[2]); double maxY = NumberUtils.createDouble(bboxArray[3]); geoCriteria = new GeospatialCriteria(minX, minY, maxX, maxY); } else { throw new UnsupportedQueryException("Invalid values found for bbox [" + box + "]"); } } catch (NumberFormatException e) { LOGGER.warn("Invalid values found for bbox [{}]. Resulted in exception: {}", box, e.getMessage()); throw new UnsupportedQueryException( "Invalid values found for bbox [" + box + "], values must be numeric."); } // Only check lat and lon. If Radius is blank is should be defaulted } else if (StringUtils.isNotBlank(lat) && StringUtils.isNotBlank(lon)) { try { double longitude = NumberUtils.createDouble(lon); double latitude = NumberUtils.createDouble(lat); double radius = StringUtils.isNotBlank(rad) ? NumberUtils.createDouble(rad) : defaultRadius; geoCriteria = new GeospatialCriteria(latitude, longitude, radius); } catch (NumberFormatException e) { LOGGER.warn( "Invalid Number found for lat [{}], lon [{}], and/or radius [{}]. Resulted in exception: {}", lat, lon, rad, e.getMessage()); throw new UnsupportedQueryException("Invalid Number found for lat [" + lat + "], lon [" + lon + "], and/or radius [" + rad + "]."); } } else if (StringUtils.isNotBlank(geom)) { try { WKTReader reader = new WKTReader(); reader.read(geom); } catch (ParseException e) { LOGGER.warn("The following is not a valid WKT String: {}", geom); throw new UnsupportedQueryException("Invalid WKT, cannot create geospatial query."); } geoCriteria = new GeospatialCriteria(geom); } else if (StringUtils.isNotBlank(polygon)) { String wkt = GeospatialUtils.polygonToWKT(polygon); try { WKTReader reader = new WKTReader(); reader.read(wkt); } catch (ParseException e) { LOGGER.warn("The following is not a valid WKT String: {}", wkt); throw new UnsupportedQueryException("Invalid WKT, cannot create geospatial query."); } geoCriteria = new GeospatialCriteria(wkt); } if (geoCriteria != null && geoRelation != null) { SpatialOperator spatialOp = SearchUtils.enumEqualsIgnoreCase(SpatialOperator.class, geoRelation); if (spatialOp != null) { geoCriteria.setSpatialOperator(spatialOp); } } return geoCriteria; }
From source file:com.moviejukebox.plugin.TheTvDBPlugin.java
@Override public boolean scan(Movie movie) { String id = findId(movie);/*from w w w. j a v a 2s. co m*/ if (StringTools.isValidString(id)) { Series series = getSeries(id); if (series == null) { LOG.debug("No series information found for {}", movie.getTitle()); } else { if (OverrideTools.checkOverwriteTitle(movie, THETVDB_PLUGIN_ID)) { movie.setTitle(series.getSeriesName(), THETVDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteOriginalTitle(movie, THETVDB_PLUGIN_ID)) { movie.setOriginalTitle(series.getSeriesName(), THETVDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteYear(movie, THETVDB_PLUGIN_ID)) { String year = getYear(id, movie.getSeason(), LANGUAGE_PRIMARY); if (StringTools.isNotValidString(year) && StringTools.isValidString(LANGUAGE_SECONDARY)) { year = getYear(id, movie.getSeason(), LANGUAGE_SECONDARY); } movie.setYear(year, THETVDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteReleaseDate(movie, THETVDB_PLUGIN_ID)) { // Set the release date to be the series first aired date movie.setReleaseDate(series.getFirstAired(), THETVDB_PLUGIN_ID); } if (isNotValidString(movie.getShowStatus())) { // Set the show status movie.setShowStatus(series.getStatus()); } if (movie.getRating(THETVDB_PLUGIN_ID) == -1 && StringUtils.isNotBlank(series.getRating())) { try { movie.addRating(THETVDB_PLUGIN_ID, (int) (Float.parseFloat(series.getRating()) * 10)); } catch (NumberFormatException ex) { LOG.trace("Failed to transform rating for series id {} = '{}', Error: {}", series.getId(), series.getRating(), ex.getMessage()); } } if (OverrideTools.checkOverwriteRuntime(movie, THETVDB_PLUGIN_ID)) { movie.setRuntime(series.getRuntime(), THETVDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteCompany(movie, THETVDB_PLUGIN_ID)) { movie.setCompany(series.getNetwork(), THETVDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteGenres(movie, THETVDB_PLUGIN_ID)) { movie.setGenres(series.getGenres(), THETVDB_PLUGIN_ID); } if (OverrideTools.checkOverwritePlot(movie, THETVDB_PLUGIN_ID)) { movie.setPlot(series.getOverview(), THETVDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteCertification(movie, THETVDB_PLUGIN_ID)) { movie.setCertification(series.getContentRating(), THETVDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteActors(movie, THETVDB_PLUGIN_ID)) { movie.setCast(series.getActors(), THETVDB_PLUGIN_ID); } if (OverrideTools.checkOverwritePeopleActors(movie, THETVDB_PLUGIN_ID)) { movie.setPeopleCast(series.getActors(), THETVDB_PLUGIN_ID); } if (includeWideBanners && isNotValidString(movie.getBannerURL()) || (forceBannerOverwrite) || movie.isDirty(DirtyFlag.BANNER)) { String bannerUrl = getBanner(movie); if (StringTools.isValidString(bannerUrl)) { movie.setBannerURL(bannerUrl); LOG.trace("Used banner {}", bannerUrl); } } getFanart(movie); scanTVShowTitles(movie); } } return Boolean.TRUE; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.filtering.MultipleCutOffFilteringController.java
/** * Private methods and classes/*from w w w .j av a2 s.c o m*/ */ // initialize the main view private void initMainView() { // make a new view multipleCutOffPanel = new MultipleCutOffPanel(); // make a new radio button group for the radio buttons ButtonGroup radioButtonGroup = new ButtonGroup(); radioButtonGroup.add(multipleCutOffPanel.getPixelRadioButton()); radioButtonGroup.add(multipleCutOffPanel.getMicroMeterRadioButton()); // pixels or m? multipleCutOffPanel.getPixelRadioButton().addActionListener((ActionEvent e) -> { multipleCutOffPanel.getConversionFactorTextField().setEnabled(true); }); multipleCutOffPanel.getMicroMeterRadioButton().addActionListener((ActionEvent e) -> { // m: we do not need a conversion factor multipleCutOffPanel.getConversionFactorTextField().setEnabled(false); }); // set default to micrometer multipleCutOffPanel.getMicroMeterRadioButton().setSelected(true); // and therefore no need for the conversion factor multipleCutOffPanel.getConversionFactorTextField().setEnabled(false); // set some default values for the top and bottom translocaton limits multipleCutOffPanel.getBottomLimTextField().setText("0.4"); multipleCutOffPanel.getTopLimTextField().setText("2.8"); multipleCutOffPanel.getTranslocationStepTextField().setText("0.8"); multipleCutOffPanel.getPercentageMotileStepsTextField().setText("30"); percentageMotile = 33; // actually do the filtering multipleCutOffPanel.getFilterButton().addActionListener((ActionEvent e) -> { // try to read the user-inserted values for up and down limit // check for number format exception try { if (multipleCutOffPanel.getPixelRadioButton().isSelected()) { double conversionFactor = Double .parseDouble(multipleCutOffPanel.getConversionFactorTextField().getText()); multipleCutOffPanel.getBottomLimTextField() .setText("" + AnalysisUtils.roundTwoDecimals( Double.parseDouble(multipleCutOffPanel.getBottomLimTextField().getText()) / conversionFactor)); multipleCutOffPanel.getTopLimTextField() .setText("" + AnalysisUtils.roundTwoDecimals( Double.parseDouble(multipleCutOffPanel.getTopLimTextField().getText()) / conversionFactor)); } int topLimit = (int) (Double.parseDouble(multipleCutOffPanel.getTopLimTextField().getText()) * 10); int bottomLimit = (int) (Double.parseDouble(multipleCutOffPanel.getBottomLimTextField().getText()) * 10); double step = Double.parseDouble(multipleCutOffPanel.getTranslocationStepTextField().getText()); percentageMotile = Double .parseDouble(multipleCutOffPanel.getPercentageMotileStepsTextField().getText()); int numberSteps = (int) ((topLimit - bottomLimit) / (10 * step)) + 1; motileSteps = new ArrayList<>(); for (int i = 0; i < numberSteps; i++) { motileSteps.add(((double) bottomLimit / 10) + (step * i)); } FilterSwingWorker filterSwingWorker = new FilterSwingWorker(); filterSwingWorker.execute(); } catch (NumberFormatException ex) { // warn the user and log the error for info filteringController.showMessage("Please insert valid numbers!" + "\n " + ex.getMessage(), "number format exception", JOptionPane.ERROR_MESSAGE); LOG.error(ex.getMessage()); } }); // apply a specific cut-off value to all the conditions at once multipleCutOffPanel.getApplyCutOffToConditionsButton().addActionListener((ActionEvent e) -> { // get the cut-off from the list (sure this is a Double) Double value = (Double) multipleCutOffPanel.getCutOffValuesComboBox().getSelectedItem(); FilterConditionSwingWorker filterConditionSwingWorker = new FilterConditionSwingWorker(value); filterConditionSwingWorker.execute(); }); // select cut-off for a condition multipleCutOffPanel.getSelectCutOffForConditionButton().addActionListener((ActionEvent e) -> { if (multipleCutOffPanel.getCutOffValuesComboBox().getSelectedItem() != null) { SelectCutOffConditionSwingWorker selectCutOffConditionSwingWorker = new SelectCutOffConditionSwingWorker(); selectCutOffConditionSwingWorker.execute(); } else { filteringController.showMessage("Please select a cut-off!", "info", JOptionPane.WARNING_MESSAGE); } }); AlignedTableRenderer alignedTableRenderer = new AlignedTableRenderer(SwingConstants.LEFT); for (int i = 0; i < multipleCutOffPanel.getFilterTrackTable().getColumnModel().getColumnCount(); i++) { multipleCutOffPanel.getFilterTrackTable().getColumnModel().getColumn(i) .setCellRenderer(alignedTableRenderer); multipleCutOffPanel.getSummaryTable().getColumnModel().getColumn(i) .setCellRenderer(alignedTableRenderer); } multipleCutOffPanel.getFilterTrackTable().getTableHeader() .setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); multipleCutOffPanel.getSummaryTable().getTableHeader() .setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); // add view to parent component filteringController.getFilteringPanel().getMultipleCutOffParentPanel().add(multipleCutOffPanel, gridBagConstraints); }
From source file:jp.massbank.spectrumsearch.logic.MassBankRecordLogic.java
public void mergeMassBankRecordIntoDb(File mbFile, List<Instrument> instruments, List<MsType> msTypes) { // read the file content long s = System.currentTimeMillis(); MassBankRecord massBankRecord = getFileRecordByFile(mbFile); if (massBankRecord.isAvailable()) { try {/*from w ww. jav a2 s. co m*/ // INSTRUMENT Instrument oInstrument = null; for (Instrument instrument : instruments) { if (instrument.getType().equals(massBankRecord.getAcInstrument().getType())) { oInstrument = instrument; } } // merge INSTRUMENT if not exist if (oInstrument == null) { Instrument instrument = new Instrument(); instrument.setType(massBankRecord.getAcInstrument().getType()); this.instrumentAccessor.insert(instrument); oInstrument = this.instrumentAccessor.getInstrument(massBankRecord.getAcInstrument().getType()); instruments.add(oInstrument); } // MS_TYPE String strMsType = massBankRecord.getAcMassSpectrometryMap().get("MS_TYPE"); MsType oMsType = null; for (MsType msType : msTypes) { if (msType.getName().equals(strMsType)) { oMsType = msType; } } // merge MS_TYPE if not exist if (oMsType == null) { MsType msType = new MsType(); msType.setName(strMsType); this.msTypeAccessor.insert(msType); oMsType = this.msTypeAccessor.getMsTypeByName(strMsType); msTypes.add(oMsType); } DbAccessor.setAutoCommit(false); // RECORD Compound compound = new Compound(); compound.setId(massBankRecord.getId()); compound.setTitle(massBankRecord.getTitle()); compound.setFormula(massBankRecord.getChFormula()); compound.setExactMass(massBankRecord.getChExtractMass()); String strIonMode = massBankRecord.getAcMassSpectrometryMap().get("ION_MODE"); if (StringUtils.isNotBlank(strIonMode)) { compound.setIonMode(IonMode.parseInt(strIonMode)); } compound.setInstrumentId(oInstrument.getId()); compound.setMsId(oMsType.getId()); this.compoundAccessor.addBatchInsert(compound); // for (String name : massBankRecord.getChNames()) { // CompoundName compoundName = new CompoundName(); // compoundName.setName(name); // compoundName.setCompoundId(massBankRecord.getId()); // this.compoundNameAccessor.addBatchInsert(compoundName); // } /*// MASS_SPECTROMETRY if (massBankRecord.getAcMassSpectrometryMap() != null) { List<MassSpectrometry> massSpectrometries = new ArrayList<MassSpectrometry>(); for (Entry<String, String> entry : massBankRecord.getAcMassSpectrometryMap().entrySet()) { MassSpectrometry massSpectrometry = new MassSpectrometry(); massSpectrometry.setType(entry.getKey()); massSpectrometry.setValue(entry.getValue()); massSpectrometry.setRecordId(massBankRecord.getId()); } if (massSpectrometries.size() > 0) { // massSpectrometryAccessor.addBatchInsert(massSpectrometries); massSpectrometryAccessor.executeBatchInsert(massSpectrometries); } }*/ // PEAK if (massBankRecord.getPkPeak().getPeakMap() != null) { List<Peak> peaks = new ArrayList<Peak>(); for (Map<String, String> pValue : massBankRecord.getPkPeak().getPeakMap()) { Peak peak = new Peak(); peak.setMz(Double.parseDouble(pValue.get("m/z"))); peak.setIntensity(Double.parseDouble(pValue.get("int."))); peak.setRelativeIntensity(Integer.parseInt(pValue.get("rel.int."))); peak.setCompoundId(massBankRecord.getId()); peaks.add(peak); } if (peaks.size() > 0) { this.peakAccessor.executeBatchInsert(peaks); // this.peakAccessor.addBatchInsert(peaks); } } try { String strPrecursorMz = massBankRecord.getMsFocusedIonMap().get("PRECURSOR_M/Z"); if (strPrecursorMz == null) { strPrecursorMz = StringUtils.EMPTY; } String[] strPrecursorMzArray = strPrecursorMz.split("/"); for (String oStrPrecursorMz : strPrecursorMzArray) { if (StringUtils.isNotBlank(oStrPrecursorMz)) { Precursor precursor = new Precursor(); precursor.setPrecursorMz(Float.parseFloat(oStrPrecursorMz)); precursor.setCompoundId(massBankRecord.getId()); this.precursorAccessor.addBatchInsert(precursor); } // // SPECTRUM // String strIonMode = massBankRecord.getAcMassSpectrometryMap().get("ION_MODE"); // if (StringUtils.isNotBlank(strPrecursorMz) && StringUtils.isNotBlank(strIonMode)) { // Spectrum spectrum = new Spectrum(); // spectrum.setTitle(massBankRecord.getTitle()); // spectrum.setPrecursorMz(Float.parseFloat(oStrPrecursorMz)); // spectrum.setIonMode(IonMode.parseInt(strIonMode)); // spectrum.setRecordId(massBankRecord.getId()); // this.spectrumAccessor.addBatchInsert(spectrum); // } else { // LOGGER.warn("No Spectrum Info.: " + massBankRecord.getId()); // } } } catch (NumberFormatException e) { LOGGER.error(e.getMessage(), e); } LOGGER.debug("before executeBatch (" + mbFile.getName() + ") - " + (System.currentTimeMillis() - s) + "ms"); DbAccessor.executeBatchAndCloseStatment(); LOGGER.debug("after executeBatch (" + mbFile.getName() + ") - " + (System.currentTimeMillis() - s) + "ms"); // commit DbAccessor.commit(); DbAccessor.setAutoCommit(true); LOGGER.debug( "after commit (" + mbFile.getName() + ") - " + (System.currentTimeMillis() - s) + "ms"); } catch (SQLException e) { LOGGER.error("error in file:" + mbFile.getPath()); LOGGER.error(e.getMessage(), e); try { DbAccessor.rollback(); } catch (SQLException e1) { LOGGER.error(e.getMessage(), e); } } finally { } } }
From source file:com.eyekabob.jaxrs.Event.java
protected String getResponseByID(String id) { JSONObject response = new JSONObject(); if (id == null) { return getJSONError("Error", "ID was [" + id + "]"); }//from www.j a v a2 s . co m int intId; try { intId = Integer.parseInt(id); } catch (NumberFormatException e) { return getJSONError("Error", "ID [" + id + "] was not an int"); } Connection conn = null; String error = null; try { String query = "SELECT id,name FROM event WHERE id=?"; JSONObject event = new JSONObject(); List<Map<String, Object>> eventResults = DBUtils.query(query, intId); for (Map<String, Object> row : eventResults) { // There should only be one row. event.put("id", row.get("id")); event.put("name", row.get("name")); } response.put("event", event); } catch (SQLException e) { error = getJSONError(SQLException.class.getSimpleName(), e.getMessage()); } catch (JSONException e) { error = getJSONError(JSONException.class.getSimpleName(), e.getMessage()); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { error = getJSONError(SQLException.class.getSimpleName(), e.getMessage()); } } } if (error != null) { return error; } return response.toString(); }
From source file:com.cellbots.communication.CustomHttpCommChannel.java
@Override public void listenForMessages(final long waitTimeBetweenPolling, final boolean returnStream) { if (inUrl == null || doDisconnect) return;/* ww w . j a v a 2 s.c om*/ stopReading = false; listenThread = new Thread(new Runnable() { @Override public void run() { Looper.prepare(); while (!stopReading) { try { if (waitTimeBetweenPolling >= 0) Thread.sleep(waitTimeBetweenPolling); if (commandUrl == null) { commandUrl = new URL(inUrl); } URLConnection cn = commandUrl.openConnection(); cn.connect(); if (returnStream) { if (mMessageListener != null) { mMessageListener.onMessage(new CommMessage(null, cn.getInputStream(), null, null, null, mChannelName, CommunicationManager.CHANNEL_HTTP)); } } else { BufferedReader rd = new BufferedReader(new InputStreamReader(cn.getInputStream()), 1024); String cmd = rd.readLine(); if (cmd != null && !cmd.equals(prevCmd) && mMessageListener != null) { prevCmd = cmd; // TODO (chaitanyag): Change this after we come // up with a better protocol. The first (space // separated) token in the command string could // be a timestamp. This is useful if the same // commands are sent back to back. For example, // the controller sends consecutive "hu" // (head up) commands to tilt the head up in // small increments. if (cmd.indexOf(' ') >= 0) { try { Long.parseLong(cmd.substring(0, cmd.indexOf(' '))); cmd = cmd.substring(cmd.indexOf(' ') + 1); } catch (NumberFormatException e) { } } mMessageListener.onMessage(new CommMessage(cmd, null, null, null, null, mChannelName, CommunicationManager.CHANNEL_HTTP)); } } if (waitTimeBetweenPolling < 0) { // Do not repeat this loop break; } } catch (MalformedURLException e) { Log.e(TAG, "Error processing URL: " + e.getMessage()); } catch (IOException e) { Log.e(TAG, "Error reading command from URL: " + commandUrl + " : " + e.getMessage()); } catch (InterruptedException e) { e.printStackTrace(); } } } }); listenThread.start(); }
From source file:classification.SentimentClassification.java
/** * @param doc/*ww w .j a v a2s. co m*/ * @param sentenceLevelAnnotation * @param docContent * @param currentSentenceLevel */ private void extractOrientationTermPhrases(Document doc, Annotation sentenceLevelAnnotation, DocumentContent docContent, SentimentSentence currentSentenceLevel) { if (sentenceLevelAnnotation.getFeatures().containsKey("OrientationTermPhrase")) { String orienttionTermFeatureString = sentenceLevelAnnotation.getFeatures().get("OrientationTermPhrase") .toString(); String[] orientationTermIDs = splitFeatureString(orienttionTermFeatureString); for (String currentID : orientationTermIDs) { try { log.info("Extract OrientationTermPhrase with currentID: " + currentID); currentID = currentID.trim(); Integer otID = null; try { otID = Integer.valueOf(currentID); } catch (NumberFormatException nfex) { log.error("Cannot extract Orientationterm Gate ID from String: " + otID); throw new NumberFormatException("Cannot extract Orientationterm Gate ID from String: " + otID + "\n" + nfex.getMessage()); } Phrase orientationPhrase = extractPhrase(doc.getAnnotations().get(otID), docContent, "Orientation", databaseConn.getConstantEntites().getOrientationPhraseType()); currentSentenceLevel.getOrientationTermPhraseList().add(orientationPhrase); } catch (NumberFormatException nfex) { log.error(nfex.getMessage()); log.error("Continue with next orientationTerm"); continue; } } } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.webSiteManager.CustomUnitSiteManagementDA.java
private Integer getId(String id) { if (id == null || id.equals("")) { return null; }// w w w .j a va 2 s .com try { return new Integer(id); } catch (NumberFormatException e) { logger.error(e.getMessage(), e); return null; } }
From source file:gov.nih.nci.cabig.caaers.web.ae.StudyInterventionsTab.java
public ModelAndView removeAgent(HttpServletRequest request, Object command, Errors errors) { AbstractExpeditedAdverseEventInputCommand cmd = (AbstractExpeditedAdverseEventInputCommand) command; List<CourseAgent> agents = cmd.getAeReport().getTreatmentInformation().getCourseAgents(); int index;/* ww w .j a v a 2 s. co m*/ try { index = Integer.parseInt(request.getParameter("index")); } catch (NumberFormatException e) { index = -1; log.debug("Wrong <index> for <agents> list: " + e.getMessage()); } if (agents.size() - 1 < index) { log.debug("Wrong <index> for <agents> list."); } else if (index >= 0) { cmd.deleteAttribution(agents.get(index)); agents.remove(agents.get(index)); } ; int size = agents.size(); Integer[] indexes = new Integer[size]; for (int i = 0; i < size; i++) { indexes[i] = size - (i + 1); } ModelAndView modelAndView = new ModelAndView("ae/ajax/courseAgentFormSection"); modelAndView.getModel().put("agents", agents); modelAndView.getModel().put("indexes", indexes); return modelAndView; }
From source file:gov.nih.nci.cabig.caaers.web.ae.StudyInterventionsTab.java
public ModelAndView removeDevice(HttpServletRequest request, Object command, Errors errors) { ExpeditedAdverseEventInputCommand cmd = (ExpeditedAdverseEventInputCommand) command; List<MedicalDevice> devices = cmd.getAeReport().getMedicalDevices(); int index;//w w w. j av a2s. c o m try { index = Integer.parseInt(request.getParameter("index")); } catch (NumberFormatException e) { index = -1; log.debug("Wrong <index> for <devices> list: " + e.getMessage()); } if (devices.size() - 1 < index) { log.debug("Wrong <index> for <devices> list."); } else if (index >= 0) { MedicalDevice object = (MedicalDevice) devices.get(index); devices.remove(object); deleteAttributions(object, (ExpeditedAdverseEventInputCommand) command); } int size = devices.size(); Integer[] indexes = new Integer[size]; for (int i = 0; i < size; i++) { indexes[i] = size - (i + 1); } ModelAndView modelAndView = new ModelAndView("ae/ajax/medicalDeviceFormSection"); modelAndView.getModel().put("devices", devices); modelAndView.getModel().put("indexes", indexes); return modelAndView; }