List of usage examples for java.util Calendar compareTo
private int compareTo(long t)
From source file:hsa.awp.campaign.facade.CampaignFacade.java
@Transactional @Override//from ww w.j av a 2s . c om public List<Procedure> findActiveProcedureSince(Calendar since) { if (since == null) { return procedureDao.findActive(); } if (since.compareTo(Calendar.getInstance()) > 0) { throw new IllegalArgumentException("since data has to be before now."); } return procedureDao.findActiveSince(since); }
From source file:org.kuali.kra.committee.service.impl.CommitteeServiceImpl.java
/** * Is the member available for the given schedule meeting date? * The member must have a role for that date. * @param member the member/*from w w w .ja v a 2 s . c om*/ * @param scheduledDate the date of the meeting * @return true if the member will be at the meeting; otherwise false * TODO: This method calls member.isActive() and then carries out date checking that has * already been performed in member.isActive()? Perhaps this method should be removed and * its invocation in getAvailableMembers() above should be replaced by a single * call to member.isActive(schedule.getScheduledDate()) */ protected boolean isMemberAvailable(CommitteeMembership member, Date scheduledDate) { java.sql.Date sqlDate = new java.sql.Date(scheduledDate.getTime()); if (member.isActive(sqlDate)) { Calendar scheduleCalendar = getCalendar(scheduledDate); List<CommitteeMembershipRole> roles = member.getMembershipRoles(); for (CommitteeMembershipRole role : roles) { Calendar startCalendar = getCalendar(role.getStartDate()); Calendar endCalendar = getCalendar(role.getEndDate()); if (scheduleCalendar.compareTo(startCalendar) >= 0 && scheduleCalendar.compareTo(endCalendar) <= 0) { return true; } } } return false; }
From source file:org.sofun.core.kup.policy.KupActiveLifeCyclePolicyManager.java
/** * Kup life cycle management.// w ww. j ava 2s. c om * * @throws Exception */ @Schedule(minute = "*/4", hour = "*", persistent = false) public void check() throws Exception { if (!available) { return; } else { available = false; } try { log.debug("Checking Kups and apply policy..."); final byte[] activesAndCreated = new byte[3]; activesAndCreated[0] = KupStatus.CREATED; activesAndCreated[1] = KupStatus.OPENED; activesAndCreated[2] = KupStatus.ON_GOING; final List<Kup> activeKups = kups.getKupsByStatus(activesAndCreated, null); final Calendar ref = getReferenceTime(); ListIterator<Kup> kupsIter = activeKups.listIterator(); while (kupsIter.hasNext()) { Kup kup = kupsIter.next(); // Ensure no changes have been made by another transaction in // the mean time. em.refresh(kup); if (KupStatus.CREATED == kup.getStatus()) { final Calendar startDate = Calendar.getInstance(); startDate.setTime(kup.getStartDate()); if (ref.compareTo(startDate) >= 0) { kup.setStatus(KupStatus.OPENED); log.info("Kup with id=" + String.valueOf(kup.getId()) + " has now status=" + KupStatus.OPENED); } } else if (KupStatus.OPENED == kup.getStatus()) { final Calendar startDate = Calendar.getInstance(); startDate.setTime(kup.getEffectiveStartDate()); if (ref.compareTo(startDate) >= 0) { boolean cancelled = false; if (kup.getParticipants().size() < 2) { // Cancel gambling Kup if only one (1) participant. if (KupType.GAMBLING_FR.equals(kup.getType())) { kups.cancelKup(kup); log.info("Kup with id=" + String.valueOf(kup.getId()) + " has been cancelled because the " + "number of participants is < 2"); cancelled = true; } } if (!cancelled) { kup.setStatus(KupStatus.ON_GOING); log.info("Kup with id=" + String.valueOf(kup.getId()) + " has now status=" + KupStatus.ON_GOING); } } } else if (KupStatus.ON_GOING == kup.getStatus()) { final Calendar endDate = Calendar.getInstance(); // Kup is closed if the last event of the Kup is less // than 5 minutes to begin. endDate.setTime(kup.getEffectiveEndDate()); if (ref.compareTo(endDate) >= 0) { Map<Integer, Float> repartition = kups.getWinningsRepartitionRulesFor(kup); final int numberOfWinners = repartition.size(); boolean cancelled = false; if (kup.getParticipants().size() < numberOfWinners) { // Cancel gambling Kup participants below amount of // announced winners. if (KupType.GAMBLING_FR.equals(kup.getType())) { kups.cancelKup(kup); log.info("Kup with id=" + String.valueOf(kup.getId()) + " has been cancelled because the " + "number of participants is < 2"); cancelled = true; } } if (!cancelled) { kup.setStatus(KupStatus.CLOSED); log.info("Kup with id=" + String.valueOf(kup.getId()) + " has now status=" + KupStatus.CLOSED); } } } } } catch (Throwable t) { log.error(t.getMessage()); t.printStackTrace(); } finally { available = true; } // Cancel status in exceptional situations will be handled manually per // administrator request. // @see KupeService.cancelKup() }
From source file:com.denimgroup.threadfix.importer.impl.remoteprovider.WhiteHatSourceRemoteProvider.java
@Override public List<Scan> getScans(RemoteProviderApplication remoteProviderApplication) { LOG.info("Retrieving a WhiteHat Source scan."); apiKey = getAuthenticationFieldValue(API_KEY); String appName = remoteProviderApplication.getNativeName(); String siteId = remoteProviderApplication.getNativeId(); if (siteId == null) { LOG.warn("No build ID was parsed."); return null; // we failed. } else {/*from w ww . j a v a 2 s. c o m*/ LOG.info("Retrieved build ID " + siteId + " for application " + appName); } saxFindingList = list(); String url = APPLICATIONS_URL + siteId + "/vuln/?key=" + apiKey + EXTRA_PARAMS_OPEN; LOG.info("Requesting open findings from site ID " + siteId); getFindingsFromUrl(url); LOG.info("Got " + saxFindingList.size() + " open findings from site ID " + siteId); url = APPLICATIONS_URL + siteId + "/vuln/?key=" + apiKey + EXTRA_PARAMS_CLOSED; LOG.info("Requesting closed findings from site ID " + siteId); getFindingsFromUrl(url); LOG.info("Got " + saxFindingList.size() + " open and closed findings from site ID " + siteId); List<Scan> scanList = list(); Collections.sort(scanDateList); List<Finding> newScanFindings; for (Calendar d : scanDateList) { date = d; newScanFindings = list(); for (Finding originalFinding : saxFindingList) { Finding finding = new Finding(originalFinding); if (findingStatusMap.containsKey(finding.getNativeId())) { FindingStatus findingStatus = findingStatusMap.get(finding.getNativeId()); if (d.compareTo(findingStatus.getOpenedDate()) >= 0) { // Checking if Finding is open at this time if (OPEN_STATUS.equals(findingStatus.getStatus())) { newScanFindings.add(finding); } else if (findingStatus.getClosedDate() != null && findingStatus.getClosedDate().after(d)) { newScanFindings.add(finding); } } } } scanList.add(makeNewScan(newScanFindings)); } if (scanList == null || scanList.size() == 0) { LOG.error("No scan was parsed, something is broken."); return null; } LOG.info("WhiteHat " + " scans successfully parsed."); return filterScans(scanList); }
From source file:nz.co.jsrsolutions.ds3.command.UpdateExchangeQuotesCommand.java
public boolean execute(Context context) throws Exception { logger.info("Executing: updateexchangequotes"); final String exchange = (String) context.get(CommandContext.EXCHANGE_KEY); if (exchange == null) { throw new CommandException("Must supply --exchange [exchangecode]"); }// w w w .j ava 2 s . c om long nQuotesWritten = 0; final int availableMonths = _eodDataProvider.getExchangeMonths(exchange); final String[] symbols = _eodDataSink.readExchangeSymbols(exchange); if (symbols == null) { logger.info("No symbols associated with this exchange..."); return false; } final Collection<Future<Long>> futures = new LinkedList<Future<Long>>(); for (String symbol : symbols) { final Calendar firstAvailableDateTime = Calendar.getInstance(); if (availableMonths > 0) { firstAvailableDateTime.add(Calendar.MONTH, -1 * availableMonths); firstAvailableDateTime.add(Calendar.DATE, 1); } final Calendar today = Calendar.getInstance(); final Range<Calendar> sinkRange = _eodDataSink.readExchangeSymbolDateRange(exchange, symbol); final ArrayList<Range<Calendar>> requestRangesList = new ArrayList<Range<Calendar>>(2); if (sinkRange != null) { if (firstAvailableDateTime.compareTo(sinkRange.getLower()) < 0) { // In this implementation we can't ask for this! /* final Calendar upper = (Calendar) sinkRange.getLower().clone(); upper.add(Calendar.DATE, -1); final Calendar lower = (firstAvailableDateTime.compareTo(upper) < 0) ? firstAvailableDateTime : upper; requestRangesList.add(new Range<Calendar>(firstAvailableDateTime, upper)); // TODO: implement prepend in Hd5 Sink */ } if (today.compareTo(sinkRange.getUpper()) > 0) { final Calendar lower = (Calendar) sinkRange.getUpper().clone(); lower.add(Calendar.DATE, 1); // TODO: fix this by observing timezones final Calendar upper = (Calendar) today.clone(); // cheat for now with upper bound on today (anywhere in the world!) upper.add(Calendar.DATE, 1); requestRangesList.add(new Range<Calendar>(lower, upper)); } } else { requestRangesList.add(new Range<Calendar>(firstAvailableDateTime, today)); } for (Range<Calendar> requestRange : requestRangesList) { if (logger.isInfoEnabled()) { StringBuffer logMessageBuffer = new StringBuffer(); logMessageBuffer.setLength(0); logMessageBuffer.append(" Attempting to retrieve quotes on [ "); logMessageBuffer.append(exchange); logMessageBuffer.append(" ] for [ "); logMessageBuffer.append(symbol); logMessageBuffer.append(" ] between [ "); logMessageBuffer.append(requestRange.getLower().getTime().toString()); logMessageBuffer.append(" ] and [ "); logMessageBuffer.append(requestRange.getUpper().getTime().toString()); logMessageBuffer.append(" ] "); logger.info(logMessageBuffer.toString()); } try { futures.add(_executorService.submit(new ReadWriteQuotesTask(_eodDataProvider, _eodDataSink, exchange, symbol, requestRange.getLower(), requestRange.getUpper()))); } catch (Exception e) { logger.error("Task submission failed", e); } } } for (Future<Long> future : futures) { try { nQuotesWritten += future.get(); } catch (ExecutionException e) { logger.error("Execution exception: ", e); } catch (InterruptedException e) { logger.error("Interrupted exception: ", e); } } if (_emailService != null) { final StringBuffer subjectBuffer = new StringBuffer(); subjectBuffer.append("Updated quotes on "); subjectBuffer.append(exchange); final StringBuffer messageBuffer = new StringBuffer(); messageBuffer.append("Wrote "); messageBuffer.append(nQuotesWritten); messageBuffer.append(" quotes over "); messageBuffer.append(symbols.length); messageBuffer.append(" symbols "); _emailService.send(subjectBuffer.toString(), messageBuffer.toString()); } return false; }
From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java
private boolean isBirthdayAfterDateHired(ActionRequest actionRequest) { boolean isBirthdayAfterDateHired = true; Calendar birthdayCal = MyAccountUtil .getCalendarFromDate(MyAccountRequestUtil.getBirthdayFromRequest(actionRequest)); Calendar newHiredCal = MyAccountUtil.getCalendarFromDate(MyAccountRequestUtil.getDateHired(actionRequest)); if ((birthdayCal != null) && (newHiredCal != null) && (birthdayCal.compareTo(newHiredCal) >= 0)) { String userId = ParamUtil.getString(actionRequest, "userId"); SessionErrors.add(actionRequest, "birthday-after-hire"); isBirthdayAfterDateHired = false; logger.error("Date hired cannot be BEFORE user's birthday: " + userId); }/*from w w w . ja v a 2 s . co m*/ return isBirthdayAfterDateHired; }
From source file:com.cttapp.bby.mytlc.layer8apps.CalendarHandler.java
private ArrayList<Shift> checkForDuplicates(ArrayList<Shift> newShifts) { Preferences pf = new Preferences(this); ArrayList<String> oldShifts = pf.getSavedShifts(); ContentResolver cr = getContentResolver(); for (String id : oldShifts) { Cursor cursor = cr.query(getEventsUri(), new String[] { "dtstart", "dtend" }, "CALENDAR_ID = " + calID + " AND _ID = " + id, null, null); if (!cursor.moveToFirst()) { continue; }//w ww . ja va 2s.c o m do { Calendar now = Calendar.getInstance(); Calendar startTime = Calendar.getInstance(); startTime.setTimeInMillis(cursor.getLong(0)); Calendar endTime = Calendar.getInstance(); endTime.setTimeInMillis(cursor.getLong(1)); if (endTime.compareTo(now) == -1) { deleteShift(id); continue; } boolean shiftFound = false; for (Shift shift : newShifts) { if (shift.getStartDate().get(Calendar.HOUR_OF_DAY) == startTime.get(Calendar.HOUR_OF_DAY) && shift.getEndDate().get(Calendar.MINUTE) == shift.getEndDate().get(Calendar.MINUTE)) { newShifts.remove(shift); shiftFound = true; break; } } if (!shiftFound) { cr.delete(getEventsUri(), "CALENDAR_ID = " + calID + " AND _ID = " + String.valueOf(id), null); } } while (cursor.moveToNext()); } return newShifts; }
From source file:org.apache.oozie.coord.CoordELFunctions.java
public static Calendar getEffectiveNominalTime() { Date datasetInitialInstance = getInitialInstance(); TimeZone dsTZ = getDatasetTZ(); // Convert Date to Calendar for corresponding TZ Calendar current = Calendar.getInstance(); current.setTime(datasetInitialInstance); current.setTimeZone(dsTZ);/*from ww w . jav a 2s .c o m*/ Calendar calEffectiveTime = Calendar.getInstance(); calEffectiveTime.setTime(getActionCreationtime()); calEffectiveTime.setTimeZone(dsTZ); if (current.compareTo(calEffectiveTime) > 0) { // Nominal Time < initial Instance // TODO: getClass() call doesn't work from static method. // XLog.getLog("CoordELFunction.class").warn("ACTION CREATED BEFORE INITIAL INSTACE "+ // current.getTime()); return null; } return calEffectiveTime; }
From source file:mx.edu.um.mateo.rh.dao.impl.EmpleadoDaoHibernate.java
private Criterion getQueryByMonth(Calendar gc) { Criterion cr = null;//w w w . j a va 2 s. c om gc.add(Calendar.YEAR, 1); gc.set(Calendar.DAY_OF_MONTH, 1); Date fechaI = gc.getTime(); gc.set(Calendar.DAY_OF_MONTH, gc.getMaximum(Calendar.DAY_OF_MONTH)); Date fechaF = gc.getTime(); cr = Restrictions.between("fechaNacimiento", fechaI, fechaF); Calendar tmp = (Calendar) gc.clone(); tmp.clear(); tmp.setTime(new Date()); tmp.add(Calendar.YEAR, -17); if (gc.compareTo(tmp) <= 0) { return Restrictions.or(cr, getQueryByMonth(gc)); } else { return cr; } }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternet.CFInternetClusterHPKey.java
public int compareTo(Object obj) { if (obj == null) { return (-1); } else if (obj instanceof CFInternetClusterHBuff) { CFInternetClusterHBuff rhs = (CFInternetClusterHBuff) obj; int retval = 0; {// w w w. jav a2 s . com long lhsAuditClusterId = getAuditClusterId(); long rhsAuditClusterId = rhs.getAuditClusterId(); if (lhsAuditClusterId < rhsAuditClusterId) { return (-1); } else if (lhsAuditClusterId > rhsAuditClusterId) { return (1); } } { Calendar lhsAuditStamp = getAuditStamp(); Calendar rhsAuditStamp = rhs.getAuditStamp(); if (lhsAuditStamp == null) { if (rhsAuditStamp != null) { return (-1); } } else if (rhsAuditStamp == null) { return (1); } else { int cmpstat = lhsAuditStamp.compareTo(rhsAuditStamp); if (cmpstat != 0) { return (cmpstat); } } } { short lhsAuditActionId = getAuditActionId(); short rhsAuditActionId = rhs.getAuditActionId(); if (lhsAuditActionId < rhsAuditActionId) { return (-1); } else if (lhsAuditActionId > rhsAuditActionId) { return (1); } } { int lhsRequiredRevision = getRequiredRevision(); int rhsRequiredRevision = rhs.getRequiredRevision(); if (lhsRequiredRevision < rhsRequiredRevision) { return (-1); } else if (lhsRequiredRevision > rhsRequiredRevision) { return (1); } } { UUID lhsAuditSessionId = getAuditSessionId(); UUID rhsAuditSessionId = rhs.getAuditSessionId(); if (lhsAuditSessionId == null) { if (rhsAuditSessionId != null) { return (-1); } } else if (rhsAuditSessionId == null) { return (1); } else { int cmpstat = lhsAuditSessionId.compareTo(rhsAuditSessionId); if (cmpstat != 0) { return (cmpstat); } } } if (getRequiredId() < rhs.getRequiredId()) { return (-1); } else if (getRequiredId() > rhs.getRequiredId()) { return (1); } return (0); } else if (obj instanceof CFInternetClusterHPKey) { CFInternetClusterHPKey rhs = (CFInternetClusterHPKey) obj; { long lhsAuditClusterId = getAuditClusterId(); long rhsAuditClusterId = rhs.getAuditClusterId(); if (lhsAuditClusterId < rhsAuditClusterId) { return (-1); } else if (lhsAuditClusterId > rhsAuditClusterId) { return (1); } } { Calendar lhsAuditStamp = getAuditStamp(); Calendar rhsAuditStamp = rhs.getAuditStamp(); if (lhsAuditStamp == null) { if (rhsAuditStamp != null) { return (-1); } } else if (rhsAuditStamp == null) { return (1); } else { int cmpstat = lhsAuditStamp.compareTo(rhsAuditStamp); if (cmpstat != 0) { return (cmpstat); } } } { short lhsAuditActionId = getAuditActionId(); short rhsAuditActionId = rhs.getAuditActionId(); if (lhsAuditActionId < rhsAuditActionId) { return (-1); } else if (lhsAuditActionId > rhsAuditActionId) { return (1); } } { int lhsRequiredRevision = getRequiredRevision(); int rhsRequiredRevision = rhs.getRequiredRevision(); if (lhsRequiredRevision < rhsRequiredRevision) { return (-1); } else if (lhsRequiredRevision > rhsRequiredRevision) { return (1); } } { UUID lhsAuditSessionId = getAuditSessionId(); UUID rhsAuditSessionId = rhs.getAuditSessionId(); if (lhsAuditSessionId == null) { if (rhsAuditSessionId != null) { return (-1); } } else if (rhsAuditSessionId == null) { return (1); } else { int cmpstat = lhsAuditSessionId.compareTo(rhsAuditSessionId); if (cmpstat != 0) { return (cmpstat); } } } if (getRequiredId() < rhs.getRequiredId()) { return (-1); } else if (getRequiredId() > rhs.getRequiredId()) { return (1); } return (0); } else if (obj instanceof CFInternetHPKey) { CFInternetHPKey rhs = (CFInternetHPKey) obj; { long lhsAuditClusterId = getAuditClusterId(); long rhsAuditClusterId = rhs.getAuditClusterId(); if (lhsAuditClusterId < rhsAuditClusterId) { return (-1); } else if (lhsAuditClusterId > rhsAuditClusterId) { return (1); } } { Calendar lhsAuditStamp = getAuditStamp(); Calendar rhsAuditStamp = rhs.getAuditStamp(); if (lhsAuditStamp == null) { if (rhsAuditStamp != null) { return (-1); } } else if (rhsAuditStamp == null) { return (1); } else { int cmpstat = lhsAuditStamp.compareTo(rhsAuditStamp); if (cmpstat != 0) { return (cmpstat); } } } { short lhsAuditActionId = getAuditActionId(); short rhsAuditActionId = rhs.getAuditActionId(); if (lhsAuditActionId < rhsAuditActionId) { return (-1); } else if (lhsAuditActionId > rhsAuditActionId) { return (1); } } { int lhsRequiredRevision = getRequiredRevision(); int rhsRequiredRevision = rhs.getRequiredRevision(); if (lhsRequiredRevision < rhsRequiredRevision) { return (-1); } else if (lhsRequiredRevision > rhsRequiredRevision) { return (1); } } { UUID lhsAuditSessionId = getAuditSessionId(); UUID rhsAuditSessionId = rhs.getAuditSessionId(); if (lhsAuditSessionId == null) { if (rhsAuditSessionId != null) { return (-1); } } else if (rhsAuditSessionId == null) { return (1); } else { int cmpstat = lhsAuditSessionId.compareTo(rhsAuditSessionId); if (cmpstat != 0) { return (cmpstat); } } } return (0); } else if (obj instanceof CFInternetClusterPKey) { CFInternetClusterPKey rhs = (CFInternetClusterPKey) obj; if (getRequiredId() < rhs.getRequiredId()) { return (-1); } else if (getRequiredId() > rhs.getRequiredId()) { return (1); } return (0); } else if (obj instanceof CFInternetClusterBuff) { CFInternetClusterBuff rhs = (CFInternetClusterBuff) obj; if (getRequiredId() < rhs.getRequiredId()) { return (-1); } else if (getRequiredId() > rhs.getRequiredId()) { return (1); } return (0); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), "compareTo", "obj", obj, "CFInternetClusterHPKey, CFInternetClusterPKey, CFInternetClusterBuff"); } }