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.libreplan.web.reports.SchedulingProgressPerOrderController.java

public void checkCannotBeHigher(Datebox dbStarting, Datebox dbEnding) {
    dbStarting.clearErrorMessage(true);//from ww w.j av a  2s  .  c  o m
    dbEnding.clearErrorMessage(true);

    final Date startingDate = dbStarting.getValue();
    final Date endingDate = dbEnding.getValue();

    if (endingDate != null && startingDate != null && startingDate.compareTo(endingDate) > 0) {
        throw new WrongValueException(dbStarting, _("Cannot be higher than Ending Date"));
    }
}

From source file:com.epam.ipodromproject.service.MainService.java

@Transactional
public boolean makeBet(User user, Competition competitionToBet, String money, BetType betType, String horseID) {
    if ((!userService.canMakeBet(user.getUsername(), money, competitionToBet))
            || (!horseService.existsHorseInCompetition(competitionToBet, horseID))) {
        return false;
    }/* w w  w . j a v  a 2 s  . c om*/
    Date now = new Date();
    Horse horse = horseService.getHorseByID(Long.valueOf(horseID));
    double moneyToBet = Double.parseDouble(money);
    if ((CompetitionState.NOT_REGISTERED.equals(competitionToBet.getState()))
            && (now.compareTo(competitionToBet.getDateOfStart()) <= 0)) {
        Double coefficient = returnCoefficientDueToBetType(
                competitionToBet.getHorses().get(horse).getCoefficient(), betType);
        Bet betInfo = new Bet(moneyToBet, new Date(), betType, horse, user.getPerson(), competitionToBet,
                coefficient);
        betService.update(betInfo);
        userService.makeBet(user, moneyToBet);
        return true;
    } else {
        return false;
    }
}

From source file:org.eclipse.wb.internal.swing.model.property.editor.models.spinner.DateSpinnerComposite.java

@Override
public String validate() {
    Date value = m_valueField.getSelection();
    Date minimum = m_minField.getSelection();
    Date maximum = m_maxField.getSelection();
    if (m_minButton.getSelection() && minimum.compareTo(value) > 0) {
        return ModelMessages.DateSpinnerComposite_errMinValue;
    }/* ww w .  ja  v a  2  s. com*/
    if (m_maxButton.getSelection() && maximum.compareTo(value) < 0) {
        return ModelMessages.DateSpinnerComposite_errMaxValue;
    }
    // OK
    return null;
}

From source file:com.krawler.esp.servlets.importProjectPlanCSV.java

public static String getActualDuration_importCSV(Date stdate, Date enddate, int[] NonWorkDays,
        String[] holidays, String duration) {
    Double noofdays = 0.0;/*  w  w  w.java  2  s  .  c om*/
    java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd");
    try {
        Calendar c1 = Calendar.getInstance();
        while (stdate.compareTo(enddate) < 0) {
            if (Arrays.binarySearch(NonWorkDays, stdate.getDay()) < 0
                    && Arrays.binarySearch(holidays, sdf1.format(stdate)) < 0) {
                noofdays++;
            }
            c1.setTime(stdate);
            c1.add(Calendar.DATE, 1);
            stdate = sdf1.parse(sdf1.format(c1.getTime()));
        }
        if (stdate.compareTo(enddate) == 0) {
            if (Arrays.binarySearch(NonWorkDays, stdate.getDay()) < 0
                    && Arrays.binarySearch(holidays, sdf1.format(stdate)) < 0) {
                if (duration.equals("")) {
                    noofdays++;
                } else {
                    int dur1 = Integer.parseInt(duration.substring(0, 1));
                    if (dur1 == 0) {
                        noofdays = 0.0;
                    } else {
                        noofdays++;
                    }
                }
            }
        }
    } catch (ParseException ex) {
        Logger.getLogger(importProjectPlanCSV.class.getName()).log(Level.SEVERE, null, ex);
    }
    return String.valueOf(noofdays);
}

From source file:org.digidoc4j.impl.bdoc.xades.validation.TimemarkSignatureValidator.java

private void addCertificateExpirationError() {
    Date signingTime = signature.getTrustedSigningTime();
    if (signingTime == null) {
        return;//from  www.  jav  a  2s.  com
    }
    X509Certificate signerCert = signature.getSigningCertificate().getX509Certificate();
    Date notBefore = signerCert.getNotBefore();
    Date notAfter = signerCert.getNotAfter();
    boolean isCertValid = signingTime.compareTo(notBefore) >= 0 && signingTime.compareTo(notAfter) <= 0;
    if (!isCertValid) {
        logger.error("Signature has been created with expired certificate");
        addValidationError(new SignedWithExpiredCertificateException());
    }
}

From source file:ch.algotrader.esper.EngineManagerImpl.java

@Override
public Date getCurrentEPTime() {
    Date newest = null;
    for (final Engine engine : engineMap.values()) {
        if (!engine.isInternalClock()) {
            final Date current = engine.getCurrentTime();
            if (newest == null || newest.compareTo(current) < 0) {
                newest = current;/*from w w  w  .j  a  v a  2 s.  c om*/
            }
        }
    }
    return newest != null ? newest : new Date();
}

From source file:cx.ring.model.Conversation.java

public String getLastAccountUsed() {
    String last = null;/*ww w . jav a2 s .co m*/
    Date d = new Date(0);
    for (Map.Entry<String, HistoryEntry> e : history.entrySet()) {
        Date nd = e.getValue().getLastInteraction();
        if (d.compareTo(nd) < 0) {
            d = nd;
            last = e.getKey();
        }
    }
    return last;
}

From source file:org.jpos.gl.rule.CanPost.java

private void checkEntries(GLTransaction txn, Date postDate) throws GLException {
    List list = txn.getEntries();
    Iterator iter = list.iterator();
    while (iter.hasNext()) {
        GLEntry entry = (GLEntry) iter.next();
        Account acct = entry.getAccount();
        Date end = acct.getExpiration();
        if (end != null && postDate.compareTo(end) > 0) {
            throw new GLException("Account '" + acct.toString()
                    + "' cannot accept transactions with a post date greater than " + end.toString());
        }/* w  ww .ja va  2  s  .  c om*/
    }
}

From source file:fr.univrouen.poste.utils.PostePermissionEvaluator.java

@Override
public boolean hasPermission(Authentication auth, Object targetDomainObject, Object permission) {

    if (auth.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_ADMIN"))
            || auth.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_MANAGER")))
        return true;

    boolean isMembre = auth.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_MEMBRE"));
    boolean isCandidat = auth.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_CANDIDAT"));

    String permissionKey = (String) permission;

    if (auth == null || auth.getName() == null || "".equals(auth.getName()))
        return false;

    if (!(targetDomainObject instanceof PosteCandidature || targetDomainObject instanceof Long))
        return false;

    String email = auth.getName();

    if ("delFile".equals(permissionKey)) {
        Long id = (Long) targetDomainObject;
        PosteCandidatureFile pcFile = PosteCandidatureFile.findPosteCandidatureFile(id);
        return pcFile.getWriteable();
    }//from  www  .j a  va2 s .  c  o m

    if ("delMemberReviewFile".equals(permissionKey)) {
        Boolean confSupprReviewFile = AppliConfig.getCacheMembreSupprReviewFile();
        if (!confSupprReviewFile) {
            return false;
        }
        Long id = (Long) targetDomainObject;
        MemberReviewFile reviewFile = MemberReviewFile.findMemberReviewFile(id);
        User user = User.findUsersByEmailAddress(email, null, null).getSingleResult();
        return reviewFile.getMember().equals(user);
    }

    if ("manageReporters".equals(permissionKey)) {
        Long id = (Long) targetDomainObject;
        PosteCandidature pc = PosteCandidature.findPosteCandidature(id);
        User user = User.findUsersByEmailAddress(email, null, null).getSingleResult();
        return pc.getPoste().getPresidents() != null && pc.getPoste().getPresidents().contains(user);
    }

    if ("viewposte".equals(permissionKey)) {
        Long id = (Long) targetDomainObject;
        PosteAPourvoir posteAPourvoir = PosteAPourvoir.findPosteAPourvoir(id);
        User user = User.findUsersByEmailAddress(email, null, null).getSingleResult();
        return posteAPourvoir.getMembres() != null && posteAPourvoir.getMembres().contains(user);
    }

    if ("manageposte".equals(permissionKey)) {
        Long id = (Long) targetDomainObject;
        PosteAPourvoir posteAPourvoir = PosteAPourvoir.findPosteAPourvoir(id);
        User user = User.findUsersByEmailAddress(email, null, null).getSingleResult();
        return posteAPourvoir.getPresidents() != null && posteAPourvoir.getPresidents().contains(user);
    }

    if (!"manage".equals(permissionKey) && !"view".equals(permissionKey) && !"review".equals(permissionKey))
        return false;

    PosteCandidature pc;

    if (targetDomainObject instanceof PosteCandidature) {
        pc = (PosteCandidature) targetDomainObject;
    } else {
        Long id = (Long) targetDomainObject;
        pc = PosteCandidature.findPosteCandidature(id);
    }

    if (pc != null) {
        User user = User.findUsersByEmailAddress(email, null, null).getSingleResult();

        if ("review".equals(permissionKey)) {
            PosteAPourvoir poste = pc.getPoste();
            return user.getIsAdmin() || user.getIsManager()
                    || user.getIsMembre() && poste.getMembres().contains(user) && pc.getRecevable();
        }

        if (isCandidat) {

            if (AppliConfig.getCacheCandidatCanSignup()) {
                Date currentTime = new Date();
                if ((pc.getAuditionnable() || (pc.getPoste().getDateEndSignupCandidat() == null
                        || currentTime.compareTo(pc.getPoste().getDateEndSignupCandidat()) > 0))
                        && (!pc.getAuditionnable()
                                || (pc.getPoste().getDateEndCandidatAuditionnable() == null || currentTime
                                        .compareTo(pc.getPoste().getDateEndCandidatAuditionnable()) > 0))) {
                    return false;
                } else {
                    return true;
                }
            } else {

                if (pc.getCandidat().equals(user)) {
                    // restrictions si phase auditionnable
                    Date currentTime = new Date();
                    if (currentTime.compareTo(AppliConfig.getCacheDateEndCandidat()) > 0
                            && currentTime.compareTo(AppliConfig.getCacheDateEndCandidatActif()) > 0) {
                        return pc.getAuditionnable()
                                && currentTime.compareTo(pc.getPoste().getDateEndCandidatAuditionnable()) < 0;
                    } else {
                        return true;
                    }
                }
            }
        }

        if ("view".equals(permissionKey) && isMembre) {
            PosteAPourvoir poste = pc.getPoste();
            return poste.getMembres().contains(user) && pc.getRecevable();
        }
    }

    return false;

}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.database.LocalTransformationDBMS.java

public ArrayList<String> getAllAvalDate() {
    ArrayList<String> list = new ArrayList<String>();
    String q = "SELECT * FROM " + LocalTransformationDB.TABLE_DATE_TO_TRAFFIC + " ORDER BY "
            + LocalTransformationDB.COLUMN_DATE_ID + ";";
    Cursor cursor = database.rawQuery(q, null);
    if (cursor.moveToFirst()) {
        do {/*  ww w .j  a v  a  2s .c  o m*/
            String date = cursor.getString(cursor.getColumnIndex(LocalTransformationDB.COLUMN_DATE_TEXT));
            if (!list.contains(date))
                list.add(date);
        } while (cursor.moveToNext());
    }
    cursor.close();

    Collections.sort(list, new Comparator<String>() {

        @Override
        public int compare(String arg0, String arg1) {
            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
            int compareResult = 0;
            try {
                Date arg0Date = format.parse(arg0);
                Date arg1Date = format.parse(arg1);
                compareResult = arg0Date.compareTo(arg1Date);
            } catch (ParseException e) {
                e.printStackTrace();
                compareResult = arg0.compareTo(arg1);
            }
            return compareResult;
        }
    });

    for (String s : list) {
        Log.e(TAG, "AvalDate:" + s);
    }
    return list;
}