List of usage examples for java.util Date compareTo
public int compareTo(Date anotherDate)
From source file:com.kcs.action.FrwImportAction.java
public void excelToList() throws Exception { String filePath = getServletRequest().getSession().getServletContext().getRealPath("/"); try {//from w ww.j a va2s . c o m InputStream input = new BufferedInputStream(new FileInputStream(this.getToBeUploaded())); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); Iterator rows = sheet.rowIterator(); setResultsFromExcel(new ArrayList<Datasetfrw>()); int checkColName = 0; setCheckDatasetDate("true"); while (rows.hasNext()) { HSSFRow row = (HSSFRow) rows.next(); if (checkColName != 0) { Datasetfrw datasetfrw = new Datasetfrw(); Date dateFromJsp = DateUtil.convertDateFromJsp(getDataSetDate()); Date dateFromExcel = DateUtil.getDateFromString(row.getCell(1).toString(), DateUtil.DATE_FORMAT_YYYYMMDDX); if (dateFromJsp.compareTo(dateFromExcel) != 0) { setCheckDatasetDate("false"); break; } int index = 0; datasetfrw.setOrgId(row.getCell(index++).toString()); datasetfrw.setDataSetDate(convertDate(row.getCell(index++).toString())); datasetfrw.setCurrCode(row.getCell(index++).toString()); datasetfrw.setCommInLieuRateForDepsit(row.getCell(index++).toString()); datasetfrw.setMinCommInLieuForDepsit(row.getCell(index++).toString()); datasetfrw.setMaxCommInLieuForDepsit(row.getCell(index++).toString()); datasetfrw.setInwTransfFeeForDepsit(row.getCell(index++).toString()); datasetfrw.setMinInwTransfFeeForDepsit(row.getCell(index++).toString()); datasetfrw.setMaxInwTransfFeeForDepsit(row.getCell(index++).toString()); datasetfrw.setOthFeeDescForDepsit(row.getCell(index++).toString()); datasetfrw.setCommInLieuRateForWithdw(row.getCell(index++).toString()); datasetfrw.setMinCommInLieuRateFWithdw(row.getCell(index++).toString()); datasetfrw.setMaxCommInLieuRateFWithdw(row.getCell(index++).toString()); datasetfrw.setWithdwFeeForOthTransf(row.getCell(index++).toString()); datasetfrw.setEffectiveDate(convertDate(row.getCell(index++).toString())); datasetfrw.setEndDate(convertDate(row.getCell(index++).toString())); datasetfrw.setSeq(Long.valueOf(row.getCell(index++).toString())); datasetfrw.setUpdBy(getCurrentLoginId()); datasetfrw.setUpdDate(DateUtil.getCurrentDateTime()); index++; index++; datasetfrw.setSysCode(row.getCell(index++).toString()); getResultsFromExcel().add(datasetfrw); } checkColName++; } setResultsFromExcel(getResultsFromExcel()); session.put("EXCEL_TO_LIST_FRW", getResultsFromExcel()); } catch (IOException ex) { ex.printStackTrace(); logger.error("Error >>> " + ex.getMessage()); } }
From source file:com.kcs.action.OffImportAction.java
public void excelToList() throws Exception { String filePath = getServletRequest().getSession().getServletContext().getRealPath("/"); try {//from w ww . j av a 2 s . co m InputStream input = new BufferedInputStream(new FileInputStream(this.getToBeUploaded())); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); Iterator rows = sheet.rowIterator(); setResultsFromExcel(new ArrayList<Datasetoff>()); int checkColName = 0; setCheckDatasetDate("true"); while (rows.hasNext()) { HSSFRow row = (HSSFRow) rows.next(); if (checkColName != 0) { Datasetoff datasetoff = new Datasetoff(); Date dateFromJsp = DateUtil.convertDateFromJsp(getDataSetDate()); Date dateFromExcel = DateUtil.getDateFromString(row.getCell(1).toString(), DateUtil.DATE_FORMAT_YYYYMMDDX); if (dateFromJsp.compareTo(dateFromExcel) != 0) { setCheckDatasetDate("false"); break; } int index = 0; datasetoff.setOrgId(row.getCell(index++).toString()); datasetoff.setDataSetDate(convertDate(row.getCell(index++).toString())); datasetoff.setArrgmentTye(row.getCell(index++).toString()); datasetoff.setCurrCode(row.getCell(index++).toString()); datasetoff.setMinimOpenAcctAmt(row.getCell(index++).toString()); datasetoff.setMinimBalForMaintenanceFee(row.getCell(index++).toString()); datasetoff.setMaintenanceFee(row.getCell(index++).toString()); datasetoff.setInactiveTerm(convertBigDecimal(row.getCell(index++).toString())); datasetoff.setInactiveTermUnt(row.getCell(index++).toString()); datasetoff.setInactiveFee(row.getCell(index++).toString()); datasetoff.setEffectiveDate(convertDate(row.getCell(index++).toString())); datasetoff.setEndDate(convertDate(row.getCell(index++).toString())); datasetoff.setSeq(Long.valueOf(row.getCell(index++).toString())); datasetoff.setUpdBy(getCurrentLoginId()); datasetoff.setUpdDate(DateUtil.getCurrentDateTime()); index++; index++; datasetoff.setSysCode(row.getCell(index++).toString()); getResultsFromExcel().add(datasetoff); } checkColName++; } setResultsFromExcel(getResultsFromExcel()); session.put("EXCEL_TO_LIST_FRF", getResultsFromExcel()); } catch (IOException ex) { ex.printStackTrace(); logger.error("Error >>> " + ex.getMessage()); } }
From source file:org.opendatakit.aggregate.task.WatchdogWorkerImpl.java
private boolean checkUpload(FormServiceCursor fsc, UploadSubmissions uploadSubmissions, CallingContext cc) throws ODKExternalServiceException { logger.info("Checking upload for " + fsc.getExternalServiceType() + " fsc: " + fsc.getUri()); boolean activeTask = false; if (!fsc.getUploadCompleted()) { Date lastUploadDate = fsc.getLastUploadCursorDate(); Date establishmentDate = fsc.getEstablishmentDateTime(); if (establishmentDate != null && lastUploadDate == null || lastUploadDate.compareTo(establishmentDate) < 0) { // there is still work to do activeTask = true;//from w ww . jav a 2s . c o m uploadSubmissions.createFormUploadTask(fsc, true, cc); } } return activeTask; }
From source file:org.mot.common.util.DateBuilder.java
/** * @param dateA/*from w w w.j a v a 2s. c o m*/ * @param dateB * @param pattern * @return 0 if both values are the same * +1 if dateA is after dateB * -1 if dateA is before dateB */ public int compareDates(String dateA, String dateB, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); int ret = 0; Date date1; Date date2; try { date1 = sdf.parse(dateA); date2 = sdf.parse(dateB); ret = date1.compareTo(date2); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ret; }
From source file:fr.univlorraine.mondossierweb.controllers.UserController.java
/** * @return username de l'utilisateur courant *//*from www .j ava2s. co m*/ public String getCurrentUserName(String username) { //return "toto54"; UtilisateurSwap us = utilisateurSwapRepository.findOne(username); if (us != null && us.getLoginCible() != null) { //test si la date de cration du swap utilisateur n'est pas plus vieille que 1 heure Calendar dateButoire = Calendar.getInstance(); dateButoire.setTime(us.getDatCre()); dateButoire.add(Calendar.HOUR_OF_DAY, Utils.NB_HEURE_DUREE_SWAP_USER); Date d = new Date(); if (d.compareTo(dateButoire.getTime()) < 0) { //swap autorise return us.getLoginCible(); } } return username; }
From source file:nl.clockwork.mule.ebms.filter.CPAValidationFilter.java
@Override public boolean accept(MuleMessage message) { if (message.getPayload() instanceof EbMSBaseMessage) { try {/*from ww w . ja v a2 s . c o m*/ EbMSBaseMessage msg = (EbMSBaseMessage) message.getPayload(); Date now = new Date(); CollaborationProtocolAgreement cpa = ebMSDAO.getCPA(msg.getMessageHeader().getCPAId()); if (!StatusValueType.AGREED.equals(cpa.getStatus().getValue())) { message.setProperty(Constants.EBMS_ERROR, EbMSMessageUtils.createError("//Header/MessageHeader[@cpaid]", Constants.EbMSErrorCode.INCONSISTENT.errorCode(), "CPA not agreed.")); return false; } if (now.compareTo(cpa.getStart().toGregorianCalendar().getTime()) < 0 || now.compareTo(cpa.getEnd().toGregorianCalendar().getTime()) > 0) { message.setProperty(Constants.EBMS_ERROR, EbMSMessageUtils.createError("//Header/MessageHeader[@cpaid]", Constants.EbMSErrorCode.INCONSISTENT.errorCode(), "CPA invalid.")); return false; } return StatusValueType.AGREED.equals(cpa.getStatus().getValue()) && now.compareTo(cpa.getStart().toGregorianCalendar().getTime()) >= 0 && now.compareTo(cpa.getEnd().toGregorianCalendar().getTime()) <= 0; } catch (DAOException e) { throw new RuntimeException(e); } } return true; }
From source file:gov.utah.dts.det.ccl.documents.reporting.reports.InspectionsConductedReport.java
@Override public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor fileDescriptor) throws TemplateException { FindingCategoryType fCat = getFindingCategory(context); PickListValue insType = getInspectionType(context); List<Object[]> results = getResults(context); ReportTable<Integer> reportTable = new ReportTable<Integer>(); for (Object[] res : results) { String row = (String) res[1]; String column = (String) res[0]; Integer val = ((BigDecimal) res[2]).intValue(); reportTable.addRow(row);//from w ww . j ava 2s .co m reportTable.addColumn(column); reportTable.addTableDataItem(row, column, val); } setFileName(context, fileDescriptor); Document document = new Document(PAGE_SIZE, 36, 36, 36, 36); try { PdfWriter.getInstance(document, outputStream); document.open(); StringBuilder sb = new StringBuilder(); if (insType != null) { sb.append(insType.getValue()); sb.append(" "); } sb.append("Inspections Conducted"); if (fCat != null) { sb.append(" With "); sb.append(fCat.getDisplayName()); sb.append(" Findings"); } Paragraph heading = new Paragraph(sb.toString()); heading.setAlignment(Element.ALIGN_CENTER); document.add(heading); Date startDate = (Date) context.get(DATE_RANGE_START_KEY); Date endDate = (Date) context.get(DATE_RANGE_END_KEY); clearStringBuilder(sb); if (startDate.compareTo(endDate) == 0) { sb.append("On "); sb.append(DATE_FORMATTER.format(startDate)); } else { sb.append(DATE_FORMATTER.format(startDate)); sb.append(" - "); sb.append(DATE_FORMATTER.format(endDate)); } Paragraph date = new Paragraph(sb.toString(), FONT); date.setAlignment(Element.ALIGN_RIGHT); document.add(date); PdfPTable table = new PdfPTable(reportTable.getColumns().size() + 2); table.setHeaderRows(1); table.setSpacingBefore(FONT_SIZE); table.setWidthPercentage(100f); setDefaultCellAttributes(table.getDefaultCell()); table.addCell(""); for (Iterator<String> itr = reportTable.getColumns().iterator(); itr.hasNext();) { table.addCell(getHeaderCell(itr.next())); } table.addCell(getHeaderCell("Total")); int[] colTotals = new int[reportTable.getColumns().size() + 1]; for (Iterator<String> rowItr = reportTable.getRows().iterator(); rowItr.hasNext();) { String row = rowItr.next(); table.addCell(getHeaderCell(row)); int total = 0; int idx = 0; for (Iterator<String> colItr = reportTable.getColumns().iterator(); colItr.hasNext();) { String column = colItr.next(); Integer value = reportTable.getTableDataItem(row, column); if (value == null) { table.addCell(getNumberCell("0")); } else { total += value; colTotals[idx] = colTotals[idx] + value; table.addCell(getNumberCell(value.toString())); } idx++; } table.addCell(getHeaderCell(Integer.toString(total))); colTotals[colTotals.length - 1] = colTotals[colTotals.length - 1] + total; idx++; } table.addCell(getHeaderCell("Total")); for (int i = 0; i < colTotals.length; i++) { table.addCell(getHeaderCell(Integer.toString(colTotals[i]))); } document.add(table); } catch (DocumentException de) { throw new TemplateException(de); } document.close(); }
From source file:net.riezebos.thoth.configuration.ThothEnvironment.java
public Date getRefreshTimestamp(String contextName) throws ContentManagerException { Date latestRefresh = new Date(0L); synchronized (managers) { for (ContentManager contentManager : managers.values()) { Date refresh = contentManager.getLatestRefresh(); if (refresh != null && latestRefresh.compareTo(refresh) < 0) latestRefresh = refresh; }//from w ww . jav a 2 s . c o m } return latestRefresh; }
From source file:com.hybris.datahub.core.util.OutboundServiceCsvUtilsUnitTest.java
@Test public void testGetStringValueOfObject_StringValueOfUtcDateCanBeConvertedBackToOriginalDate() throws ParseException { final Date originalDate = new Date(); final String formattedDate = csvUtils.getStringValueOfObject(originalDate); final SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_FORMAT); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); final Date convertedDate = formatter.parse(formattedDate); Assert.assertTrue(originalDate.getTime() == convertedDate.getTime()); Assert.assertEquals(0, originalDate.compareTo(convertedDate)); }
From source file:com.odoo.core.service.OSyncDataUtils.java
private JSONArray checkLocalUpdatedRecords() { // Array of records which are new or need to update in local JSONArray finalRecords = new JSONArray(); try {//from w ww .jav a 2 s. c o m // Getting list of ids which are present in local database List<Integer> serverIds = new ArrayList<>(); HashMap<String, JSONObject> serverIdRecords = new HashMap<>(); JSONArray records = response.getJSONArray("records"); for (int i = 0; i < records.length(); i++) { JSONObject record = records.getJSONObject(i); if (mModel.hasServerRecord(record.getInt("id")) && mModel.isServerRecordDirty(record.getInt("id"))) { int server_id = record.getInt("id"); serverIds.add(server_id); serverIdRecords.put("key_" + server_id, record); } else { finalRecords.put(record); } } // getting local dirty records if server records length = 0 if (records.length() <= 0) { for (ODataRow row : mModel.select(new String[] {}, "_is_dirty = ? and _is_active = ? and id != ?", new String[] { "true", "true", "0" })) { serverIds.add(row.getInt("id")); } } // Comparing dirty (updated) record List<Integer> updateToServerIds = new ArrayList<>(); if (serverIds.size() > 0) { HashMap<String, String> write_dates = getWriteDate(mModel, serverIds); for (Integer server_id : serverIds) { String key = "key_" + server_id; String write_date = write_dates.get(key); ODataRow record = mModel.browse(new String[] { "_write_date" }, "id = ?", new String[] { server_id + "" }); if (record != null) { Date write_date_obj = ODateUtils.createDateObject(write_date, ODateUtils.DEFAULT_FORMAT, false); Date _write_date_obj = ODateUtils.createDateObject(record.getString("_write_date"), ODateUtils.DEFAULT_FORMAT, false); if (_write_date_obj.compareTo(write_date_obj) > 0) { // Local record is latest updateToServerIds.add(server_id); } else { if (serverIdRecords.containsKey(key)) { finalRecords.put(serverIdRecords.get(key)); } } } } } if (updateToServerIds.size() > 0) { updateToServerRecords.put(mModel.getModelName(), updateToServerIds); } } catch (Exception e) { e.printStackTrace(); } return finalRecords; }