Example usage for java.util Date compareTo

List of usage examples for java.util Date compareTo

Introduction

In this page you can find the example usage for java.util Date compareTo.

Prototype

public int compareTo(Date anotherDate) 

Source Link

Document

Compares two Dates for ordering.

Usage

From source file:org.mifos.application.meeting.business.MeetingBO.java

private void validateEndDate(final Date endDate) throws MeetingException {
    if (endDate == null || endDate.compareTo(getStartDate()) < 0) {
        throw new MeetingException(MeetingConstants.INVALID_ENDDATE);
    }// w w  w.j av  a2s .  c om
}

From source file:org.openvpms.web.component.im.edit.act.AbstractActEditor.java

/**
 * Invoked when the end time changes. Sets the value to start time if
 * end time < start time.// w w w  . j  a  v  a  2  s .c  om
 */
protected void onEndTimeChanged() {
    Date start = getStartTime();
    Date end = getEndTime();
    if (start != null && end != null) {
        if (end.compareTo(start) < 0) {
            setEndTime(start, true);
        }
    }
}

From source file:org.libreplan.web.planner.order.OrderPlanningController.java

public Constraint checkConstraintStartDate() {
    return new Constraint() {
        @Override/*from  ww  w .j  a v a2 s .  c  om*/
        public void validate(org.zkoss.zk.ui.Component comp, Object value) throws WrongValueException {
            Date startDate = (Date) value;
            if ((startDate != null) && (filterFinishDateOrderElement.getValue() != null)
                    && (startDate.compareTo(filterFinishDateOrderElement.getValue()) > 0)) {

                filterStartDateOrderElement.setRawValue(null);
                throw new WrongValueException(comp, _("must be lower than end date"));
            }
        }
    };
}

From source file:org.libreplan.web.planner.order.OrderPlanningController.java

public Constraint checkConstraintFinishDate() {
    return new Constraint() {
        @Override/*from  w w  w  .j a  v a 2s. co  m*/
        public void validate(org.zkoss.zk.ui.Component comp, Object value) throws WrongValueException {
            Date finishDate = (Date) value;
            if ((finishDate != null) && (filterStartDateOrderElement.getValue() != null)
                    && (finishDate.compareTo(filterStartDateOrderElement.getValue()) < 0)) {

                filterFinishDateOrderElement.setRawValue(null);
                throw new WrongValueException(comp, _("must be after start date"));
            }
        }

    };
}

From source file:br.com.nordestefomento.jrimum.utilix.Field.java

/**
 * <p>//from   w w  w.j  av a  2s  . co m
 * Escreve o campo no formato e tamanho especificado.
 * </p>
 * 
 * @see TextStream#write()
 * 
 * @return campo escrito
 * @since 0.2
 */
public String write() {

    String str = null;

    if (value instanceof TextStream) {

        TextStream its = (TextStream) value;

        str = its.write();

    } else if (value instanceof Date) {

        Date campoDate = (Date) value;

        if (campoDate.compareTo(DateUtil.DATE_NULL) == 0) {
            str = StringUtils.EMPTY;

        } else {
            str = format.format(value);
        }

    } else if (value instanceof BigDecimal) {
        str = StringUtils.replaceChars(value.toString(), ".", StringUtils.EMPTY);

    } else {
        str = value.toString();
    }

    str = fill(str);

    if (str.length() != length) {
        throw new IllegalArgumentException(
                "O tamaho do campo [ " + str + " ]  incompatvel com o especificado [" + length + "]!");
    }

    return StringUtil.eliminateAccent(str).toUpperCase();
}

From source file:org.apache.falcon.entity.FileSystemStorage.java

private boolean isDateInRange(Date date, Date start) {
    //ignore end ( && date.compareTo(end) <= 0 )
    return date.compareTo(start) >= 0;
}

From source file:org.apache.oozie.command.coord.CoordPushDependencyCheckXCommand.java

@Override
protected Void execute() throws CommandException {
    // this action should only get processed if current time > nominal time;
    // otherwise, requeue this action for delay execution;
    Date nominalTime = coordAction.getNominalTime();
    Date currentTime = new Date();
    if (nominalTime.compareTo(currentTime) > 0) {
        queue(new CoordPushDependencyCheckXCommand(coordAction.getId(), true),
                nominalTime.getTime() - currentTime.getTime());
        updateCoordAction(coordAction, false);
        LOG.info("[" + actionId
                + "]::CoordPushDependency:: nominal Time is newer than current time, so requeue and wait. Current="
                + DateUtils.formatDateOozieTZ(currentTime) + ", nominal="
                + DateUtils.formatDateOozieTZ(nominalTime));
        return null;
    }/*from w w w. jav  a2 s.c o m*/

    CoordInputDependency coordPushInputDependency = coordAction.getPushInputDependencies();
    CoordInputDependency coordPullInputDependency = coordAction.getPullInputDependencies();
    if (coordPushInputDependency.getMissingDependenciesAsList().size() == 0) {
        LOG.info("Nothing to check. Empty push missing dependency");
    } else {
        List<String> missingDependenciesArray = coordPushInputDependency.getMissingDependenciesAsList();
        LOG.info("First Push missing dependency is [{0}] ", missingDependenciesArray.get(0));
        LOG.trace("Push missing dependencies are [{0}] ", missingDependenciesArray);
        if (registerForNotification) {
            LOG.debug("Register for notifications is true");
        }

        try {
            Configuration actionConf = null;
            try {
                actionConf = new XConfiguration(new StringReader(coordAction.getRunConf()));
            } catch (IOException e) {
                throw new CommandException(ErrorCode.E1307, e.getMessage(), e);
            }

            boolean isChangeInDependency = true;
            boolean timeout = false;
            ActionDependency actionDependency = coordPushInputDependency
                    .checkPushMissingDependencies(coordAction, registerForNotification);
            // Check all dependencies during materialization to avoid registering in the cache.
            // But check only first missing one afterwards similar to
            // CoordActionInputCheckXCommand for efficiency. listPartitions is costly.
            if (actionDependency.getMissingDependencies().size() == missingDependenciesArray.size()) {
                isChangeInDependency = false;
            } else {
                String stillMissingDeps = DependencyChecker
                        .dependenciesAsString(actionDependency.getMissingDependencies());
                coordPushInputDependency.setMissingDependencies(stillMissingDeps);
            }

            if (coordPushInputDependency.isDependencyMet()) {
                // All push-based dependencies are available
                onAllPushDependenciesAvailable(coordPullInputDependency.isDependencyMet());
            } else {
                // Checking for timeout
                timeout = isTimeout();
                if (timeout) {
                    queue(new CoordActionTimeOutXCommand(coordAction, coordJob.getUser(),
                            coordJob.getAppName()));
                } else {
                    queue(new CoordPushDependencyCheckXCommand(coordAction.getId()),
                            getCoordPushCheckRequeueInterval());
                }
            }

            updateCoordAction(coordAction, isChangeInDependency || coordPushInputDependency.isDependencyMet());
            if (registerForNotification) {
                registerForNotification(coordPushInputDependency.getMissingDependenciesAsList(), actionConf);
            }
            if (removeAvailDependencies) {
                unregisterAvailableDependencies(actionDependency.getAvailableDependencies());
            }
            if (timeout) {
                unregisterMissingDependencies(coordPushInputDependency.getMissingDependenciesAsList(),
                        actionId);
            }
        } catch (Exception e) {
            final CallableQueueService callableQueueService = Services.get().get(CallableQueueService.class);
            if (isTimeout()) {
                LOG.debug("Queueing timeout command");
                // XCommand.queue() will not work when there is a Exception
                callableQueueService.queue(
                        new CoordActionTimeOutXCommand(coordAction, coordJob.getUser(), coordJob.getAppName()));
                unregisterMissingDependencies(missingDependenciesArray, actionId);
            } else if (coordPullInputDependency.getMissingDependenciesAsList().size() > 0) {
                // Queue again on exception as RecoveryService will not queue this again with
                // the action being updated regularly by CoordActionInputCheckXCommand
                callableQueueService.queue(
                        new CoordPushDependencyCheckXCommand(coordAction.getId(), registerForNotification,
                                removeAvailDependencies),
                        Services.get().getConf().getInt(RecoveryService.CONF_COORD_OLDER_THAN, 600) * 1000);
            }
            throw new CommandException(ErrorCode.E1021, e.getMessage(), e);
        }
    }
    return null;
}

From source file:com.kcs.action.IrfImportAction.java

public void excelToList() throws Exception {
    String filePath = servletRequest.getSession().getServletContext().getRealPath("/");
    try {/*from   www  .  ja v  a2 s .  c o  m*/
        InputStream input = new BufferedInputStream(new FileInputStream(this.toBeUploaded));

        POIFSFileSystem fs = new POIFSFileSystem(input);

        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);
        Iterator rows = sheet.rowIterator();

        resultsFromExcel = new ArrayList<Datasetirf>();

        int checkColName = 0;
        setCheckDatasetDate("true");
        while (rows.hasNext()) {
            HSSFRow row = (HSSFRow) rows.next();
            if (checkColName != 0) {

                Datasetirf datasetirf = new Datasetirf();

                Date dateFromJsp = DateUtil.convertDateFromJsp(dataSetDate);
                Date dateFromExcel = DateUtil.getDateFromString(row.getCell(1).toString(),
                        DateUtil.DATE_FORMAT_YYYYMMDDX);
                if (dateFromJsp.compareTo(dateFromExcel) != 0) {
                    setCheckDatasetDate("false");
                    break;
                }

                datasetirf.setOrgId(row.getCell(0).toString());
                datasetirf.setDataSetDate(
                        DateUtil.parse(row.getCell(1).toString(), DateUtil.DATE_FORMAT_YYYYMMDDX));
                datasetirf.setArrgmentTye(row.getCell(2).toString());
                datasetirf.setInvPartyTye(row.getCell(3).toString());
                datasetirf.setCurrCode(row.getCell(4).toString());
                datasetirf.setDepsitTerm(Long.valueOf(row.getCell(5).toString()));
                datasetirf.setDepsitTermUnt(row.getCell(6).toString());
                datasetirf.setBalTierAmt(row.getCell(7).toString());
                datasetirf
                        .setInterestRate(NumberUtil.convertToBigDecimal(row.getCell(8).toString()).setScale(2));
                datasetirf.setEffectiveDate(
                        DateUtil.parse(row.getCell(9).toString(), DateUtil.DATE_FORMAT_YYYYMMDDX));

                if (!row.getCell(10).toString().equals("null") || row.getCell(10).toString().equals(null)) {
                    datasetirf.setEndDate(
                            DateUtil.parse(row.getCell(10).toString(), DateUtil.DATE_FORMAT_YYYYMMDDX));
                } else {
                    datasetirf.setEndDate(null);
                }

                datasetirf.setSeq(Long.valueOf(row.getCell(11).toString()));
                datasetirf.setUpdBy(getCurrentLoginId());
                datasetirf.setUpdDate(DateUtil.getCurrentDateTime());
                datasetirf.setSysCode(row.getCell(14).toString());

                resultsFromExcel.add(datasetirf);

            }
            checkColName++;
        }

        setResultsFromExcel(resultsFromExcel);
        session.put("EXCEL_TO_LIST", resultsFromExcel);

    } catch (IOException ex) {
        ex.printStackTrace();
        logger.error("Error >>> " + ex.getMessage());
    }
}

From source file:controlador.ControladorReportes.java

private boolean verificarRangoFechas(PropertyChangeEvent e, JXDatePicker jxdpFecha) {
    boolean respuesta = true;
    Date desde = reportes.getJXDPDesde().getDate();
    Date hasta = reportes.getJXDPHasta().getDate();

    if (desde.compareTo(hasta) > 0) {
        jxdpFecha.setDate((Date) e.getOldValue());
        JOptionPane.showMessageDialog(reportes, "El rango de fechas no es vlido!", "Error",
                JOptionPane.ERROR_MESSAGE, null);
        respuesta = false;/*from ww w. j  a va 2 s.  c  o  m*/
    }

    return respuesta;
}

From source file:com.kcs.action.FrfImportAction.java

public void excelToList() throws Exception {
    String filePath = getServletRequest().getSession().getServletContext().getRealPath("/");
    try {//from   ww w . ja  v a2  s  . co  m
        InputStream input = new BufferedInputStream(new FileInputStream(this.toBeUploaded));

        POIFSFileSystem fs = new POIFSFileSystem(input);

        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);
        Iterator rows = sheet.rowIterator();

        setResultsFromExcel(new ArrayList<Datasetfrf>());

        int checkColName = 0;
        setCheckDatasetDate("true");
        while (rows.hasNext()) {
            HSSFRow row = (HSSFRow) rows.next();
            if (checkColName != 0) {

                Datasetfrf datasetfrf = new Datasetfrf();

                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;
                datasetfrf.setOrgId(row.getCell(index++).toString());
                datasetfrf.setDataSetDate(convertDate(row.getCell(index++).toString()));
                datasetfrf.setLoanDepsitTrnTye(row.getCell(index++).toString());
                datasetfrf.setCurrCode(row.getCell(index++).toString());
                datasetfrf.setPaymentMethod(row.getCell(index++).toString());
                datasetfrf.setBrOrBcFlg(row.getCell(index++).toString());
                datasetfrf.setCommInLieuRate(row.getCell(index++).toString());
                datasetfrf.setMinCommInLieu(row.getCell(index++).toString());
                datasetfrf.setMaxCommInLieu(row.getCell(index++).toString());
                datasetfrf.setOthFeeDesc(row.getCell(index++).toString());
                datasetfrf.setEffectiveDate(convertDate(row.getCell(index++).toString()));
                datasetfrf.setEndDate(convertDate(row.getCell(index++).toString()));
                datasetfrf.setSeq(Long.valueOf(row.getCell(index++).toString()));
                datasetfrf.setUpdBy(getCurrentLoginId());
                datasetfrf.setUpdDate(DateUtil.getCurrentDateTime());
                index++;
                index++;
                datasetfrf.setSysCode(row.getCell(index++).toString());

                getResultsFromExcel().add(datasetfrf);

            }
            checkColName++;
        }

        setResultsFromExcel(getResultsFromExcel());
        session.put("EXCEL_TO_LIST_FRF", getResultsFromExcel());

    } catch (IOException ex) {
        ex.printStackTrace();
        logger.error("Error >>> " + ex.getMessage());
    }
}