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:com.akretion.kettle.steps.terminatooor.ScriptValuesAddedFunctions.java

public static Object date2str(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    Object oRC = new Object();
    switch (ArgList.length) {
    case 0://from   w  ww  .  j  a v a 2s  .  c o  m
        throw new RuntimeException("Please provide a valid date to the function call date2str.");
    case 1:
        try {
            if (isNull(ArgList))
                return null;
            else if (isUndefined(ArgList))
                return undefinedValue;
            java.util.Date dArg1 = (java.util.Date) ArgList[0];
            if (dArg1.equals(null))
                return null;
            Format dfFormatter = new SimpleDateFormat();
            oRC = dfFormatter.format(dArg1);
        } catch (Exception e) {
            throw new RuntimeException("Could not convert to local format.");
        }
        break;
    case 2:
        try {
            if (isNull(ArgList, new int[] { 0, 1 }))
                return null;
            else if (isUndefined(ArgList, new int[] { 0, 1 }))
                return undefinedValue;
            java.util.Date dArg1 = (java.util.Date) ArgList[0];
            String sArg2 = (String) ArgList[1];
            Format dfFormatter = new SimpleDateFormat(sArg2);
            oRC = dfFormatter.format(dArg1);
        } catch (Exception e) {
            throw new RuntimeException("Could not convert to the given format.");
        }
        break;
    case 3:
        try {
            if (isNull(ArgList, new int[] { 0, 1, 2 }))
                return null;
            else if (isUndefined(ArgList, new int[] { 0, 1, 2 }))
                return undefinedValue;
            java.util.Date dArg1 = (java.util.Date) ArgList[0];
            DateFormat dfFormatter;
            String sArg2 = (String) ArgList[1];
            String sArg3 = (String) ArgList[2];
            if (sArg3.length() == 2) {
                Locale dfLocale = new Locale(sArg3.toLowerCase());
                dfFormatter = new SimpleDateFormat(sArg2, dfLocale);
                oRC = dfFormatter.format(dArg1);
            } else {
                throw new RuntimeException("Locale is not 2 characters long.");
            }
        } catch (Exception e) {
            throw new RuntimeException("Could not convert to the given local format.");
        }
        break;
    case 4:
        try {
            if (isNull(ArgList, new int[] { 0, 1, 2, 3 }))
                return null;
            else if (isUndefined(ArgList, new int[] { 0, 1, 2, 3 }))
                return undefinedValue;
            java.util.Date dArg1 = (java.util.Date) ArgList[0];
            DateFormat dfFormatter;
            String sArg2 = (String) ArgList[1];
            String sArg3 = (String) ArgList[2];
            String sArg4 = (String) ArgList[3];

            // If the timezone is not recognized, java will automatically
            // take GMT.
            TimeZone tz = TimeZone.getTimeZone(sArg4);

            if (sArg3.length() == 2) {
                Locale dfLocale = new Locale(sArg3.toLowerCase());
                dfFormatter = new SimpleDateFormat(sArg2, dfLocale);
                dfFormatter.setTimeZone(tz);
                oRC = dfFormatter.format(dArg1);
            } else {
                throw new RuntimeException("Locale is not 2 characters long.");
            }
        } catch (Exception e) {
            throw new RuntimeException("Could not convert to the given local format.");
        }
        break;
    default:
        throw new RuntimeException("The function call date2str requires 1, 2, 3, or 4 arguments.");
    }
    return oRC;
}

From source file:org.craftercms.cstudio.alfresco.dm.script.DmWorkflowServiceScript.java

protected List<DmDependencyTO> getRefAndChildOfDiffDateFromParent(String site,
        List<DmDependencyTO> submittedItems, boolean removeInPages) {
    ServicesConfig servicesConfig = getServicesManager().getService(ServicesConfig.class);
    PersistenceManagerService persistenceManagerService = getServicesManager()
            .getService(PersistenceManagerService.class);
    String siteRoot = servicesConfig.getRepositoryRootPath(site);
    List<DmDependencyTO> childAndReferences = new FastList<DmDependencyTO>();
    for (DmDependencyTO submittedItem : submittedItems) {
        List<DmDependencyTO> children = submittedItem.getChildren();
        Date date = submittedItem.getScheduledDate();
        if (children != null) {
            Iterator<DmDependencyTO> childItr = children.iterator();
            while (childItr.hasNext()) {
                DmDependencyTO child = childItr.next();
                Date pageDate = child.getScheduledDate();
                if ((date == null && pageDate != null) || (date != null && !date.equals(pageDate))) {
                    if (!submittedItem.isNow()) {
                        child.setNow(false);
                        if (date != null && (pageDate != null && pageDate.before(date))) {
                            child.setScheduledDate(date);
                        }//w w w. j  a v  a  2  s.c o  m
                    }
                    childAndReferences.add(child);
                    List<DmDependencyTO> childDeps = child.flattenChildren();
                    for (DmDependencyTO childDep : childDeps) {
                        String depPath = siteRoot + childDep.getUri();
                        ObjectStateService.State depState = persistenceManagerService.getObjectState(depPath);
                        if (ObjectStateService.State.isUpdateOrNew(depState)) {
                            childAndReferences.add(childDep);
                        }
                    }
                    child.setReference(false);
                    childItr.remove();
                    if (removeInPages) {
                        String uri = child.getUri();
                        List<DmDependencyTO> pages = submittedItem.getPages();
                        if (pages != null) {
                            Iterator<DmDependencyTO> pagesIter = pages.iterator();
                            while (pagesIter.hasNext()) {
                                DmDependencyTO page = pagesIter.next();
                                if (page.getUri().equals(uri)) {
                                    pagesIter.remove();
                                }
                            }
                        }
                    }
                }
            }
        }
        /*
         * List<DmDependencyTO> deps =
         * submittedItem.getDirectDependencies(); if (deps != null) {
         * Iterator<DmDependencyTO> depItr = deps.iterator(); while
         * (depItr.hasNext()) { DmDependencyTO dep = depItr.next(); String
         * depPath = siteRoot + dep.getUri(); ObjectStateService.State
         * depState = persistenceManagerService.getObjectState(depPath); if
         * (ObjectStateService.State.isUpdateOrNew(depState)) { Date
         * pageDate = dep.getScheduledDate(); if ( (date==null &&
         * pageDate!=null) || (date!=null && !date.equals(pageDate))) {
         * childAndReferences.add(dep); dep.setReference(false);
         * depItr.remove(); if (removeInPages) { String uri = dep.getUri();
         * List<DmDependencyTO> pages = submittedItem.getPages(); if (pages
         * != null) { Iterator<DmDependencyTO> pagesIter = pages.iterator();
         * while (pagesIter.hasNext()) { DmDependencyTO page =
         * pagesIter.next(); if (page.getUri().equals(uri)) {
         * pagesIter.remove(); } } } } } }
         * childAndReferences.addAll(getRefAndChildOfDiffDateFromParent
         * (site, dep.getDirectDependencies(), removeInPages)); } }
         */
        DependencyRules rule = new DependencyRules(site, getServicesManager());
        childAndReferences.addAll(rule.applySubmitRule(submittedItem));
    }
    return childAndReferences;
}

From source file:org.craftercms.cstudio.alfresco.dm.service.impl.DmSimpleWorkflowServiceImpl.java

public void handleReferences(String site, SubmitPackage submitpackage, DmDependencyTO dmDependencyTO,
        boolean isNotScheduled, SubmitPackage dependencyPackage, String approver, Set<String> rescheduledUris) {//,boolean isReferencePage) {
    DmContentService dmContentService = getService(DmContentService.class);
    PersistenceManagerService persistenceManagerService = getService(PersistenceManagerService.class);
    String path = dmContentService.getContentFullPath(site, dmDependencyTO.getUri());
    NodeRef node = persistenceManagerService.getNodeRef(path);
    Serializable scheduledDateValue = persistenceManagerService.getProperty(node,
            WCMWorkflowModel.PROP_LAUNCH_DATE);
    Date scheduledDate = DefaultTypeConverter.INSTANCE.convert(Date.class, scheduledDateValue);
    if (!dmDependencyTO.isSubmitted() && scheduledDate != null
            && scheduledDate.equals(dmDependencyTO.getScheduledDate())) {
        return;/*w  ww.jav  a2  s.  c  o m*/
    }
    if (!dmDependencyTO.isReference()) {
        submitpackage.addToPackage(dmDependencyTO);
    }

    DependencyRules rule = new DependencyRules(site, getServicesManager());
    Set<DmDependencyTO> dependencyTOSet;
    if (dmDependencyTO.isSubmittedForDeletion() || dmDependencyTO.isDeleted()) {
        dependencyTOSet = rule.applyDeleteDependencyRule(dmDependencyTO);
    } else {
        long start = System.currentTimeMillis();
        dependencyTOSet = rule.applySubmitRule(dmDependencyTO);
        if (logger.isDebugEnabled()) {
            long end = System.currentTimeMillis();
            logger.debug("Time to get dependencies rule = " + (end - start));
        }
    }
    for (DmDependencyTO dependencyTO : dependencyTOSet) {
        submitpackage.addToPackage(dependencyTO);
        if (!isNotScheduled) {
            dependencyPackage.addToPackage(dependencyTO);
        }
    }

    if (isRescheduleRequest(dmDependencyTO, site)) {
        rescheduledUris.add(dmDependencyTO.getUri());
    }
}

From source file:com.google.gerrit.acceptance.edit.ChangeEditIT.java

@Test
public void rebaseEdit() throws Exception {
    assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
    assertThat(/*from w ww  . ja v  a 2 s .c om*/
            modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME, RawInputUtil.create(CONTENT_NEW)))
                    .isEqualTo(RefUpdate.Result.FORCED);
    ChangeEdit edit = editUtil.byChange(change).get();
    PatchSet current = getCurrentPatchSet(changeId);
    assertThat(edit.getBasePatchSet().getPatchSetId()).isEqualTo(current.getPatchSetId() - 1);
    Date beforeRebase = edit.getEditCommit().getCommitterIdent().getWhen();
    modifier.rebaseEdit(edit, current);
    edit = editUtil.byChange(change).get();
    assertByteArray(fileUtil.getContent(projectCache.get(edit.getChange().getProject()),
            ObjectId.fromString(edit.getRevision().get()), FILE_NAME), CONTENT_NEW);
    assertByteArray(fileUtil.getContent(projectCache.get(edit.getChange().getProject()),
            ObjectId.fromString(edit.getRevision().get()), FILE_NAME2), CONTENT_NEW2);
    assertThat(edit.getBasePatchSet().getPatchSetId()).isEqualTo(current.getPatchSetId());
    Date afterRebase = edit.getEditCommit().getCommitterIdent().getWhen();
    assertThat(beforeRebase.equals(afterRebase)).isFalse();
}

From source file:org.jpos.gl.GLSession.java

private void invalidateCheckpoints(Journal journal, Account[] accounts, Date start, Date end, short[] layers)
        throws HibernateException {
    Criteria crit = session.createCriteria(Checkpoint.class).add(Expression.eq("journal", journal))
            .add(Expression.in("account", accounts));

    if (layers != null)
        crit.add(Expression.eq("layers", layersToString(layers)));
    if (start.equals(end))
        crit.add(Expression.eq("date", start));
    else {/*from w w w .java  2  s.  c  o  m*/
        crit.add(Expression.ge("date", start));
        if (end != null) {
            crit.add(Expression.le("date", end));
        }
    }
    Iterator iter = crit.list().iterator();
    while (iter.hasNext()) {
        Checkpoint cp = (Checkpoint) iter.next();
        session.delete(cp);
    }
    session.flush();
}

From source file:ch.entwine.weblounge.common.impl.content.SearchQueryImpl.java

/**
 * {@inheritDoc}//from ww  w . ja v a2  s.  c  o  m
 * 
 * @see ch.entwine.weblounge.common.content.SearchQuery#and(java.util.Date)
 */
public SearchQuery and(Date date) {
    ensureExpectation(Date.class);
    Date startDate = (Date) stack.peek();
    if (startDate.equals(date) || startDate.after(date))
        throw new IllegalStateException("End date must be after start date");
    if ("withCreationDateBetween".equals(lastMethod))
        creationDateTo = date;
    else if ("withModificationDateBetween".equals(lastMethod))
        modificationDateTo = date;
    else if ("withPublishingDateBetween".equals(lastMethod))
        publishingDateTo = date;
    clearExpectations();
    return this;
}

From source file:com.virtusa.akura.student.controller.CoCurricularActivityController.java

/**
 * Setups the faith life and academic details rating for student.
 * //from ww  w  .j  av a 2s . co  m
 * @param model the model.
 * @param date - Date
 * @param session the session.
 * @param studentId - int
 * @throws AkuraAppException - Detailed exception
 */
private void setupStudentRatingDetails(ModelMap model, HttpSession session, Date date, int studentId)
        throws AkuraAppException {

    double academicLifeAverage = 0.0;
    double faithLifeAverage = 0.0;
    double attendanceAverage = 0.0;
    if (date.equals(DateUtil.getDateTypeYearValue(Integer.toString(DateUtil.currentYearOnly())))) {
        if (session.getAttribute(AVERAGE_FAITH_LIFE_RATING) != null) {
            faithLifeAverage = (Double) session.getAttribute(AVERAGE_FAITH_LIFE_RATING);
            model.addAttribute(MODEL_ATT_STUDENT_FAITH_LIFE, (int) Math.round(faithLifeAverage));
        }
        if (session.getAttribute(AVERAGE_ACADEMIC_LIFE_RATING) != null) {
            academicLifeAverage = (Double) session.getAttribute(AVERAGE_ACADEMIC_LIFE_RATING);
            model.addAttribute(MODEL_ATT_STUDENT_ACADEMIC_LIFE, (int) Math.round(academicLifeAverage));
        }
        if (session.getAttribute(AVERAGE_ATTENDANCE_RATING) != null) {
            attendanceAverage = (Double) session.getAttribute(AVERAGE_ATTENDANCE_RATING);
            model.addAttribute(MODEL_ATT_ATTENDANCE_RATING, (int) Math.round(attendanceAverage));
        }
    } else {
        Map<String, Double> averageMap = studentLoginDelegate.populateStudentProgressBar(studentId, date);

        faithLifeAverage = averageMap.get(AVERAGE_FAITH_LIFE_RATING);
        model.addAttribute(MODEL_ATT_STUDENT_FAITH_LIFE, (int) Math.round(faithLifeAverage));

        academicLifeAverage = averageMap.get(AVERAGE_ACADEMIC_LIFE_RATING);
        model.addAttribute(MODEL_ATT_STUDENT_ACADEMIC_LIFE, (int) Math.round(academicLifeAverage));

        attendanceAverage = averageMap.get(AVERAGE_ATTENDANCE_RATING);
        model.addAttribute(MODEL_ATT_ATTENDANCE_RATING, (int) Math.round(attendanceAverage));
    }

}

From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java

public static Object date2str(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    Object oRC = new Object();
    switch (ArgList.length) {
    case 0://from ww  w  .  j a  v  a 2s  . c  om
        throw Context.reportRuntimeError("Please provide a valid date to the function call date2str.");
    case 1:
        try {
            if (isNull(ArgList))
                return null;
            else if (isUndefined(ArgList))
                return Context.getUndefinedValue();
            java.util.Date dArg1 = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class);
            if (dArg1.equals(null))
                return null;
            Format dfFormatter = new SimpleDateFormat();
            oRC = dfFormatter.format(dArg1);
        } catch (Exception e) {
            throw Context.reportRuntimeError("Could not convert to local format.");
        }
        break;
    case 2:
        try {
            if (isNull(ArgList, new int[] { 0, 1 }))
                return null;
            else if (isUndefined(ArgList, new int[] { 0, 1 }))
                return Context.getUndefinedValue();
            java.util.Date dArg1 = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class);
            String sArg2 = Context.toString(ArgList[1]);
            Format dfFormatter = new SimpleDateFormat(sArg2);
            oRC = dfFormatter.format(dArg1);
        } catch (Exception e) {
            throw Context.reportRuntimeError("Could not convert to the given format.");
        }
        break;
    case 3:
        try {
            if (isNull(ArgList, new int[] { 0, 1, 2 }))
                return null;
            else if (isUndefined(ArgList, new int[] { 0, 1, 2 }))
                return Context.getUndefinedValue();
            java.util.Date dArg1 = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class);
            DateFormat dfFormatter;
            String sArg2 = Context.toString(ArgList[1]);
            String sArg3 = Context.toString(ArgList[2]);
            if (sArg3.length() == 2) {
                Locale dfLocale = new Locale(sArg3.toLowerCase());
                dfFormatter = new SimpleDateFormat(sArg2, dfLocale);
                oRC = dfFormatter.format(dArg1);
            } else {
                throw Context.reportRuntimeError("Locale is not 2 characters long.");
            }
        } catch (Exception e) {
            throw Context.reportRuntimeError("Could not convert to the given local format.");
        }
        break;
    case 4:
        try {
            if (isNull(ArgList, new int[] { 0, 1, 2, 3 }))
                return null;
            else if (isUndefined(ArgList, new int[] { 0, 1, 2, 3 }))
                return Context.getUndefinedValue();
            java.util.Date dArg1 = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class);
            DateFormat dfFormatter;
            String sArg2 = Context.toString(ArgList[1]);
            String sArg3 = Context.toString(ArgList[2]);
            String sArg4 = Context.toString(ArgList[3]);

            // If the timezone is not recognized, java will automatically
            // take GMT.
            TimeZone tz = TimeZone.getTimeZone(sArg4);

            if (sArg3.length() == 2) {
                Locale dfLocale = new Locale(sArg3.toLowerCase());
                dfFormatter = new SimpleDateFormat(sArg2, dfLocale);
                dfFormatter.setTimeZone(tz);
                oRC = dfFormatter.format(dArg1);
            } else {
                throw Context.reportRuntimeError("Locale is not 2 characters long.");
            }
        } catch (Exception e) {
            throw Context.reportRuntimeError("Could not convert to the given local format.");
        }
        break;
    default:
        throw Context.reportRuntimeError("The function call date2str requires 1, 2, 3, or 4 arguments.");
    }
    return oRC;
}

From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java

private BoxAndWhiskerCategoryDataset getHourlyUsageDataSet() {
    // log.info("Generating activityWeekBarDataSet");
    List<ServerWideStatsRecord> hourlyUsagePattern = getHourlyUsagePattern();
    if (hourlyUsagePattern == null) {
        return null;
    }/*from w w  w .  ja  va2s  .  com*/

    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    List[] hourList = new ArrayList[24];
    for (int ii = 0; ii < 24; ii++) {
        hourList[ii] = new ArrayList();
    }

    int totalDays = 0;
    Date prevDate = null;
    for (ServerWideStatsRecord regularUsers : hourlyUsagePattern) {
        Date currDate = (Date) regularUsers.get(0);
        if (!currDate.equals(prevDate)) {
            prevDate = currDate;
            totalDays++;
        }
        hourList[(Integer) regularUsers.get(1)].add((Long) regularUsers.get(2));
    }

    for (int ii = 0; ii < 24; ii++) {
        // add zero counts, when no data for the day
        for (int jj = hourList[ii].size(); jj < totalDays; jj++) {
            hourList[ii].add(Long.valueOf(0));
        }

        dataset.add(hourList[ii], "Last 30 days", "" + ii);
    }

    return dataset;
}