Example usage for java.util Date equals

List of usage examples for java.util Date equals

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares two dates for equality.

Usage

From source file:DateUtil.java

/**
 * Returns true if endDate is after startDate or if startDate equals endDate.
 * Returns false if either value is null.  If equalOK, returns true if the
 * dates are equal.//from  w w  w.  j a v a  2  s  . c  o m
 **/
public static boolean isValidDateRange(Date startDate, Date endDate, boolean equalOK) {
    // false if either value is null
    if (startDate == null || endDate == null) {
        return false;
    }

    if (equalOK) {
        // true if they are equal
        if (startDate.equals(endDate)) {
            return true;
        }
    }

    // true if endDate after startDate
    if (endDate.after(startDate)) {
        return true;
    }

    return false;
}

From source file:org.webcurator.ui.common.validation.ValidatorUtil.java

/**
 * Helper method to validated that a start time is before and 
 * not the same as an end time./*from  w  w  w.ja v  a  2  s .c o  m*/
 * @param aErrors the errors object to populate 
 * @param aStart the start time
 * @param aEnd the end time
 * @param aErrorCode the error code
 * @param aValues the values to set in the error message
 * @param aFailureMessage the default failure message
 */
public static void validateStartBeforeEndTime(Errors aErrors, Date aStart, Date aEnd, String aErrorCode,
        Object[] aValues, String aFailureMessage) {
    if (aStart != null && aEnd != null) {
        if (aStart.after(aEnd)) {
            aErrors.reject(aErrorCode, aValues, aFailureMessage);
        }

        if (aStart.equals(aEnd)) {
            aErrors.reject(aErrorCode, aValues, aFailureMessage);
        }
    }
}

From source file:com.sccl.attech.common.utils.DateUtils.java

/**
 * ??//from  w w  w. j  ava  2 s.com
 * @param startTime
 * @param endTime
 * @return
 * @throws ParseException
 */
public static Boolean isBetweenTime(Date startTime, Date endTime) {

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String current = formatter.format(new Date()); //?
    Date start;
    Date end;
    Date currentTime;
    try {
        start = formatter.parse(formatter.format(startTime));
        end = formatter.parse(formatter.format(endTime));
        currentTime = formatter.parse(current);
        return ((currentTime.before(end) && currentTime.after(start)) || currentTime.equals(start)
                || currentTime.equals(end));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return false;

}

From source file:com.ibm.soatf.tool.ValidateTransferedValues.java

public static boolean validateValuesFromFile(File sqlScriptFile, File messageFile, Map<String, String> mappings)
        throws FileNotFoundException, ParseException, java.text.ParseException {
    if (sqlScriptFile == null || messageFile == null || !sqlScriptFile.exists() || !messageFile.exists()) {
        throw new FileNotFoundException();
    }//from   w ww. ja va2s . c o m

    ZqlParser zqlParser = new ZqlParser();
    zqlParser.addCustomFunction("TO_DATE", 2);

    zqlParser.initParser(new FileInputStream(sqlScriptFile));

    ZStatement zs = zqlParser.readStatement();
    System.out.println("Input statement: " + zs.toString());

    boolean valid = true;
    if (zs instanceof ZQuery) {

        System.out.println("Je to select statement");
    } else if (zs instanceof ZInsert) {
        System.out.println("Je to insert statement");
        ZInsert zi = (ZInsert) zs;
        int i = 0;
        Vector columns = zi.getColumns();
        Vector values = zi.getValues();

        Enumeration colEnum = columns.elements();
        Enumeration valEnum = values.elements();
        String dbColumnName = null;
        String dbValue = null;
        String messageElementName = null;
        String messageValue = null;

        Pattern pattern = Pattern.compile("'([^']+)'");

        while (colEnum.hasMoreElements()) {

            boolean dateCompare = false;
            dbColumnName = colEnum.nextElement().toString();
            if (mappings != null && mappings.containsKey(dbColumnName)) {
                messageElementName = mappings.get(dbColumnName);
                if (messageElementName == null || "".equals(messageElementName)) {
                    //null v toColumnName - neporovnavam
                    logger.debug("Skipping column " + dbColumnName);
                    valEnum.nextElement();
                    continue;
                }
            } else {
                messageElementName = constructXMLElementNameFromDBColumn(dbColumnName);
            }
            dbValue = valEnum.nextElement().toString();
            if (dbValue != null && dbValue.startsWith("TO_DATE"))
                dateCompare = true;
            Matcher matcher = pattern.matcher(dbValue);
            if (matcher.find()) {
                dbValue = matcher.group(1);
            }
            logger.debug("Comparing values for column " + dbColumnName + " and coresponding element "
                    + messageElementName);
            messageValue = getElementFromFile(messageElementName, messageFile, false);
            boolean differ = false;
            if (dateCompare) {
                final Date dbDate = DatabaseComponent.DATE_FORMAT.parse(dbValue);
                //TODO: timezone //Date xmlDate = DatatypeConverter.parseDate(messageValue).getTime();
                Date xmlDate = (messageValue == null || messageValue.length() < 19) ? null
                        : JmsComponent.DATE_FORMAT.parse(messageValue.substring(0, 19));
                differ ^= dbDate.equals(xmlDate);
            } else {
                if (dbValue == null) {
                    if (messageValue != null) {
                        differ = true;
                    } else {
                        differ = false;
                    }
                } else {
                    differ = !dbValue.equals(messageValue);
                }
            }
            if (differ) {
                logger.debug("values are different: " + dbValue + " <> " + messageValue);
                valid = false;
            } else {
                logger.debug("values are equal");
            }
        }

    }
    return valid;
}

From source file:jp.co.ctc_g.jse.core.validation.util.Validators.java

/**
 * ??????????????/*from  w  w  w.j a  va  2s .com*/
 * @param suspect 
 * @param target ?
 * @return ?????????false
 */
public static boolean afterEqualsTo(Date suspect, Date target) {
    if (suspect == null)
        return true;
    return suspect.after(target) || suspect.equals(target);
}

From source file:org.kalypso.kalypsomodel1d2d.sim.ResultManager.java

public static String getFolderForDate(final Date stepDate) {
    final String stepResultFolder;
    if (stepDate.equals(ISimulation1D2DConstants.STEADY_DATE))
        stepResultFolder = ISimulation1D2DConstants.STEADY_PREFIX;
    else if (stepDate.equals(ISimulation1D2DConstants.MAXI_DATE))
        stepResultFolder = ISimulation1D2DConstants.MAXI_PREFIX;
    else {//from   w w w  . j  a  v  a  2 s.  co  m
        final SimpleDateFormat timeFormatter = new SimpleDateFormat(
                ResultMeta1d2dHelper.FULL_DATE_TIME_FORMAT_RESULT_STEP);
        stepResultFolder = ResultMeta1d2dHelper.TIME_STEP_PREFIX + timeFormatter.format(stepDate);
    }
    return stepResultFolder;
}

From source file:jp.co.ctc_g.jse.core.validation.util.Validators.java

/**
 * ???????????????//from   www .  j a  va2 s.c  om
 * @param suspect 
 * @param target ?
 * @return ??????????false
 */
public static boolean beforeEqualsTo(Date suspect, Date target) {
    if (suspect == null)
        return true;
    return suspect.before(target) || suspect.equals(target);
}

From source file:org.apache.lens.cube.parse.CandidateTableResolver.java

private static boolean isColumnAvailableTill(@NonNull final Date date, Date endTime) {
    return (endTime == null) || (date.equals(endTime) || date.before(endTime));
}

From source file:org.apache.lens.cube.parse.CandidateTableResolver.java

private static boolean isColumnAvailableFrom(@NonNull final Date date, Date startTime) {
    return (startTime == null) || (date.equals(startTime) || date.after(startTime));
}

From source file:org.opendatakit.aggregate.form.FormFactory.java

/**
 * Return the list of forms in the database.
 * If topLevelAuri is null, return all forms. Otherwise, return the form with the matching URI.
 * This is the main interface to the cache of form objects.  The cache is refreshed as a whole
 * every PersistConsts.MAX_SETTLE_MILLISECONDS.
 *
 * @param topLevelAuri/*from   ww  w . j  a va 2 s .c  o m*/
 * @param cc
 * @return
 * @throws ODKOverQuotaException
 * @throws ODKDatastoreException
 */
private static synchronized final List<IForm> internalGetForms(String topLevelAuri, CallingContext cc)
        throws ODKOverQuotaException, ODKDatastoreException {

    List<IForm> forms = new ArrayList<IForm>();
    if (cacheTimestamp + PersistConsts.MAX_SETTLE_MILLISECONDS > System.currentTimeMillis()) {
        // TODO: This cache should reside in MemCache.  Right now, different running
        // servers might see different Form definitions for up to the settle time.
        //
        // Since the datastore is treated as having a settle time of MAX_SETTLE_MILLISECONDS,
        // we should rely on the cache for that time interval.  Without MemCache-style
        // support, this is somewhat problematic since different server instances might
        // see different versions of the same Form.
        //
        logger.info("FormCache: using cached list of Forms");
    } else {
        // we have a fairly stale list of forms -- interrogate the database
        // for what is really there and update the cache.
        Map<String, IForm> oldForms = new HashMap<String, IForm>();
        for (IForm f : cache) {
            oldForms.put(f.getUri(), f);
        }
        cache.clear();
        logger.info("FormCache: fetching new list of Forms");

        Datastore ds = cc.getDatastore();
        User user = cc.getCurrentUser();

        FormInfoTable relation = FormInfoTable.assertRelation(cc);
        // ensure that Form table exists...
        Query formQuery = ds.createQuery(relation, "Form.getForms", user);
        List<? extends CommonFieldsBase> infoRows = formQuery.executeQuery();

        for (CommonFieldsBase cb : infoRows) {
            FormInfoTable infoRow = (FormInfoTable) cb;
            IForm f = oldForms.get(infoRow.getUri());
            // rely on the fact that a persist updates the last-update-date of the
            // top-level FormInfoTable even if only subordinate values are updated.
            Date infoDate = infoRow.getLastUpdateDate();
            Date oldDate = (f == null) ? null : f.getLastUpdateDate();
            if (f != null && f.hasValidFormDefinition()
                    && (infoRow.getCreationDate().equals(f.getCreationDate()))
                    && ((infoDate == null && oldDate == null)
                            || (infoDate != null && oldDate != null && infoDate.equals(oldDate)))) {
                cache.add(f);
            } else {
                logger.info("FormCache: refreshing form definition from database: "
                        + infoRow.getStringField(FormInfoTable.FORM_ID));
                // pull and update from the datastore
                f = new Form(infoRow, cc);
                cache.add(f);
            }
        }

        // sort by form title then by form id
        Collections.sort(forms, new Comparator<IForm>() {

            @Override
            public int compare(IForm o1, IForm o2) {
                int ref = o1.getViewableName().compareToIgnoreCase(o2.getViewableName());
                if (ref != 0)
                    return ref;
                return o1.getFormId().compareToIgnoreCase(o2.getFormId());
            }
        });

        // update cacheTimestamp -- note that if the datastore is very slow, this will
        // space out the updates because the cacheTimestamp is established after all
        // the datastore accesses.
        cacheTimestamp = System.currentTimeMillis();

        // test to see if we need to trigger the watchdog
        BackendActionsTable.triggerWatchdog(cc);
    }

    Datastore ds = cc.getDatastore();
    User user = cc.getCurrentUser();

    AclTable relation = AclTable.assertRelation(ds, user);
    Query entryQuery = ds.createQuery(relation, "Form.getFormsEntry", user);
    entryQuery.addFilter(AclTable.SID, Query.FilterOperation.EQUAL, user.getId());
    entryQuery.addFilter(AclTable.OBJECT_CLASS, Query.FilterOperation.EQUAL,
            AclTable.ProtectedClasses.FORM.getType());
    entryQuery.addFilter(AclTable.GRANTED, Query.FilterOperation.EQUAL, true);
    List<AclTable> entryRows = (List<AclTable>) entryQuery.executeQuery();

    logger.debug("Appling object-based access protection.");
    for (IForm v : cache) {
        if (topLevelAuri == null || v.getUri().equals(topLevelAuri)) {
            Long main_id = v.getId();
            for (AclTable entry : entryRows) {
                Long entryId = entry.getLongField(AclTable.OBJECT_IDENTITY);
                if (main_id == entryId) {
                    logger.debug("Check succesful!");
                    forms.add(v);
                    break;
                }
            }
        }
    }
    return forms;
}