List of usage examples for java.util Calendar compareTo
private int compareTo(long t)
From source file:org.kuali.kfs.module.tem.document.validation.impl.MileageRateRule.java
/** * Verifies that the effective to date on the mileage rate is not set to any day earlier than today * @param mileageRate the mileage rate to check * @return true if the effective date is null or set to today or in the future; false otherwise *//*from w w w . j av a 2s.co m*/ protected boolean checkActiveToDate(MileageRate mileageRate) { if (mileageRate.getActiveToDate() == null) { return true; } final DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class); final Calendar today = dateTimeService.getCurrentCalendar(); Calendar activeToDate = Calendar.getInstance(); activeToDate.setTimeInMillis(mileageRate.getActiveToDate().getTime()); if (!KfsDateUtils.isSameDay(today, activeToDate) && activeToDate.compareTo(today) < 0) { putFieldError(TemPropertyConstants.ACTIVE_TO_DATE, TemKeyConstants.ERROR_DOCUMENT_MILEAGE_RATE_INVALID_ACTIVE_TO_DATE, new String[] { dateTimeService.toDateString(mileageRate.getActiveToDate()) }); return false; } return true; }
From source file:hsa.awp.scire.controller.TestController.java
@Test public void testCall() { Set<Class<? extends IProcedureLogic<?>>> types = new HashSet<Class<? extends IProcedureLogic<?>>>(); types.add(LogicDummy.class); controller.setProcedureLogicTypeList(types); int interval = 500; controller.setTimerInterval(interval); Campaign camp = Campaign.getInstance(0L); Calendar endShow = Calendar.getInstance(); endShow.roll(Calendar.YEAR, 1); camp.setStartShow(Calendar.getInstance()); camp.setName("123"); camp.setEndShow(endShow);/* w w w . j a v a2 s .com*/ campaignFacade.saveCampaign(camp); FifoProcedure p = FifoProcedure.getInstance(0L); Calendar startDate = Calendar.getInstance(); startDate.add(Calendar.SECOND, 2); Calendar endDate = Calendar.getInstance(); while (startDate.compareTo(endDate) >= 0) { endDate.add(Calendar.SECOND, 5); } p.setInterval(startDate, endDate); campaignFacade.saveFifoProcedure(p); camp.addProcedure(p); campaignFacade.updateCampaign(camp); controller.startTimer(); int i = 0; boolean foundStarted = false; boolean foundTerminated = false; LogicDummy dummy = null; while (i++ < 300) { if (foundStarted) { if (controller.findActiveLogicByProcedure(p.getId()) == null) { foundTerminated = true; logger.info("found started procedure"); break; } } else if (controller.findActiveLogicByProcedure(p.getId()) != null) { foundStarted = true; dummy = (LogicDummy) controller.findActiveLogicByProcedure(p.getId()); logger.info("found terminated procedure"); } try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } assertTrue(foundStarted); assertTrue(foundTerminated); assertTrue(dummy.getAfterActiveCount() > 0); assertTrue(dummy.getBeforeActiveCount() > 0); assertTrue(dummy.getWhileActiveCount() > 0); controller.stopTimer(); }
From source file:org.openhab.binding.unifi.internal.handler.UniFiClientThingHandler.java
private synchronized boolean isClientHome(UniFiClient client) { boolean online = false; if (client != null) { Calendar lastSeen = client.getLastSeen(); if (lastSeen == null) { logger.warn("Could not determine if client is online: cid = {}, lastSeen = null", config.getClientID()); } else {/*from w w w . java 2 s.c o m*/ Calendar considerHome = (Calendar) lastSeen.clone(); considerHome.add(Calendar.SECOND, config.getConsiderHome()); Calendar now = Calendar.getInstance(); online = (now.compareTo(considerHome) < 0); } } return online; }
From source file:be.vdab.util.Datum.java
@Override public int compareTo(Datum d) { Calendar datum1 = new GregorianCalendar(jaar, maand - 1, dag); Calendar datum2 = new GregorianCalendar(d.jaar, d.maand - 1, d.dag); //System.out.println("compareTo: " + datum1.compareTo(datum2)); return datum1.compareTo(datum2); }
From source file:com.evozon.evoportal.myaccount.worker.UpdateUserPMReportsIntegration.java
protected boolean hasPMReportsParamatersModified() { DetailsManager detailsManager = new DetailsManager(oldAccountModelHolder.getDetailsModel(), newAccountModelHolder.getDetailsModel()); if (detailsManager.isEmailAddressChanged()) { return true; }// w w w .j av a 2 s .c o m if (detailsManager.isLastNameChanged()) { return true; } if (detailsManager.isFirstNameChanged()) { return true; } if (detailsManager.isLicensePlateChanged()) { return true; } if (detailsManager.isPhoneNumberChanged()) { return true; } Calendar oldStartDate = MyAccountUtil .resetToMidnight(oldAccountModelHolder.getFreeDaysModel().getStartDate()); Calendar newStartDate = MyAccountUtil .resetToMidnight(newAccountModelHolder.getFreeDaysModel().getStartDate()); if (oldStartDate.compareTo(newStartDate) != 0) { return true; } EvoAddressModel oldPrimaryAddress = oldAccountModelHolder.getPrimaryAddress(); EvoAddressModel newPrimaryAddress = newAccountModelHolder.getPrimaryAddress(); if ((oldPrimaryAddress == null) && (newPrimaryAddress == null)) { return false; } else if ((oldPrimaryAddress != null) && (newPrimaryAddress == null)) { return true; } else if ((oldPrimaryAddress == null) && (newPrimaryAddress != null)) { return true; } EvoAddressManager addressManager = new EvoAddressManager(oldPrimaryAddress, newPrimaryAddress); if (addressManager.isStreetNameChanged()) { return true; } if (addressManager.isStreetNumberChanged()) { return true; } if (addressManager.isCityChanged()) { return true; } if (addressManager.isCountryCodeChanged()) { return true; } return false; }
From source file:net.sf.farrago.namespace.sfdc.SfdcUdx.java
public static void getDeleted(String objectName, String start, String end, PreparedStatement resultInserter) throws SQLException { SoapBindingStub binding = (SoapBindingStub) FarragoUdrRuntime.getDataServerRuntimeSupport(null); if (((start == null) || start.equals("")) || ((end == null) || end.equals(""))) { throw SfdcResource.instance().InvalidRangeException.ex(); }/*from w ww.j a va2 s . c o m*/ Calendar startTime; Calendar endTime; Calendar thirtyDaysAgo; try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); java.util.Date sd = sdf.parse(start, new ParsePosition(0)); startTime = Calendar.getInstance(); startTime.setTime(sd); java.util.Date now = new java.util.Date(); // 30 days == 30*24*60*60*1000 ms Long thirty = new Long("2592000000"); java.util.Date thirtyDate = new java.util.Date(now.getTime() - thirty.longValue()); thirtyDaysAgo = Calendar.getInstance(); thirtyDaysAgo.setTime(thirtyDate); java.util.Date ed = sdf.parse(end, new ParsePosition(0)); endTime = Calendar.getInstance(); endTime.setTime(ed); } catch (Exception ex) { ex.printStackTrace(); throw SfdcResource.instance().InvalidTimeException.ex(ex.getMessage()); } if (thirtyDaysAgo.compareTo(startTime) > 0) { throw SfdcResource.instance().InvalidStartTimeException.ex(startTime.getTime().toString()); } if (startTime.compareTo(endTime) > 0) { throw SfdcResource.instance().InvalidEndTimeException.ex(endTime.getTime().toString(), startTime.getTime().toString()); } SfdcDataServer server = (SfdcDataServer) FarragoUdrRuntime.getDataServerRuntimeSupport(new Object()); try { DescribeSObjectResult describeSObjectResult = (DescribeSObjectResult) server .getEntityDescribe(objectName); // check the name if ((describeSObjectResult != null) && describeSObjectResult.getName().equals(objectName)) { // check if data replication is allowed on object if (!describeSObjectResult.isReplicateable()) { throw SfdcResource.instance().ReplicationException.ex(objectName); } } else { throw SfdcResource.instance().InvalidObjectException.ex(objectName); } GetDeletedResult gdr = binding.getDeleted(objectName, startTime, endTime); if ((gdr.getDeletedRecords() != null) && (gdr.getDeletedRecords().length > 0)) { for (int i = 0; i < gdr.getDeletedRecords().length; i++) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); StringBuffer sbuf = new StringBuffer(); String idString = gdr.getDeletedRecords(i).getId(); int prec = 25 + server.getVarcharPrecision(); if (idString.length() > prec) { idString = idString.substring(0, prec); } resultInserter.setString(1, idString); String timeStr = sdf .format(gdr.getDeletedRecords(i).getDeletedDate().getTime(), sbuf, new FieldPosition(0)) .toString(); resultInserter.setTimestamp(2, java.sql.Timestamp.valueOf(timeStr)); resultInserter.executeUpdate(); } } } catch (AxisFault ae) { SQLException retryExcn = new SQLException(ae.getFaultString(), null, 460150); Exception chainedEx = FarragoResource.instance().RetryableFailure.ex(retryExcn); throw SfdcResource.instance().BindingCallException.ex(ae.getFaultString(), chainedEx); } catch (RemoteException re) { SQLException retryExcn = new SQLException(re.getMessage(), null, 460150); Exception chainedEx = FarragoResource.instance().RetryableFailure.ex(retryExcn); throw SfdcResource.instance().BindingCallException.ex(re.getMessage(), chainedEx); } }
From source file:de.codesourcery.eve.skills.ui.utils.CalendarWidget.java
public void refreshDateLabel(Date date) { final Calendar stripped = de.codesourcery.eve.skills.util.Misc.stripToDay(date); if (stripped.compareTo(startDate) < 0) { throw new IllegalArgumentException("Date " + stripped + " is before start date " + startDate.getTime()); }/*from www . ja va 2s .c o m*/ if (stripped.compareTo(getEndDate()) > 0) { throw new IllegalArgumentException("Date " + stripped + " is after end date " + getEndDate()); } final long MILLIS_PER_DAY = 1000 * 60 * 60 * 24; final int deltaInDays = (int) ((stripped.getTimeInMillis() - startDate.getTimeInMillis()) / MILLIS_PER_DAY); final int y = (int) (deltaInDays / 7.0); final int x = deltaInDays - (y * 7); buttons[y][x].redraw(); }
From source file:org.starfishrespect.myconsumption.server.business.stats.StatisticsUpdater.java
/** * Cycle through each period of a given sensor to compute its associated stats. * * @param id sensor id of the sensor/*from w w w . j a v a 2s. c o m*/ * @param today today's date at midnight * @throws DaoException thrown if something goes wrong while communicating with the db */ private void computeStatsForSensor(String id, Date today) throws DaoException { // Find latest DayStat available in db // Start by getting all stats sorted for this sensor id List<DayStat> dayStats = mDayStatRepository.findBySensorId(id); Collections.sort(dayStats, new DayStatComparator()); Date dayDb; // If nothing has been found, the first day will be the first value of the sensor if (dayStats.size() == 0) { dayDb = mSensorRepository.getSensor(id).getFirstValue(); } else { // else the first day will be the latest day found in db DayStat lastDayStat = dayStats.get(dayStats.size() - 1); dayDb = lastDayStat.getDay(); } Calendar firstDay = StatUtils.date2Calendar(StatUtils.getDateAtMidnight(dayDb)); Calendar last = StatUtils.date2Calendar(today); // Compute the stat for each day starting at first day Calendar currentDay = StatUtils.date2Calendar(firstDay.getTime()); while (last.compareTo(currentDay) > 0) { computeStatForDay(id, StatUtils.calendar2TimeStamp(currentDay)); currentDay.add(Calendar.DATE, 1); } // if the current day in db has already been processed, return if (!(firstDay.getTimeInMillis() < today.getTime())) return; // Update each period updatePeriod(id, firstDay.getTime()); }
From source file:br.msf.commons.persistence.springframework.validation.AnnotatedEntityValidator.java
private void extraValidations(String fieldPath, Field field, T target, Errors errors) throws Exception { final Object fieldValue = field.get(target); final MinValue minValue = field.getAnnotation(MinValue.class); final MaxValue maxValue = field.getAnnotation(MaxValue.class); if (isNotNullCharSequence(fieldValue)) { final CharSequence val = (CharSequence) fieldValue; if (minValue != null && CharSequenceUtils.compare(val, minValue.value()) < 0) { errors.rejectValue(fieldPath, minValue.errorCode(), null, minValue.errorCode()); return; }//from ww w .j a va 2 s . co m if (maxValue != null && CharSequenceUtils.compare(val, maxValue.value()) > 0) { errors.rejectValue(fieldPath, maxValue.errorCode(), null, maxValue.errorCode()); } } else if (isNotNullCalendar(fieldValue)) { final Calendar c1 = (Calendar) fieldValue; if (minValue != null) { final Calendar c2 = CalendarUtils.parse(minValue.value(), minValue.pattern()); if (c1.compareTo(c2) < 0) { errors.rejectValue(fieldPath, minValue.errorCode(), new Object[] { minValue.value() }, minValue.errorCode()); return; } } if (maxValue != null) { final Calendar c2 = CalendarUtils.parse(maxValue.value(), maxValue.pattern()); if (c1.compareTo(c2) > 0) { errors.rejectValue(fieldPath, maxValue.errorCode(), new Object[] { maxValue.value() }, maxValue.errorCode()); } } } }
From source file:org.kuali.coeus.common.committee.impl.service.impl.CommitteeServiceImplBase.java
/** * Is it OK to schedule a review for the given committee and schedule? */// w w w .j a va 2 s . c o m protected boolean isOkayToScheduleReview(CMT committee, CS schedule) { final Calendar now = getCalendar(new Date()); final boolean dateRangeOK = now.compareTo(getCalendar(schedule.getProtocolSubDeadline())) <= 0; final boolean statusOK = Integer.valueOf(SCHEDULED).equals(schedule.getScheduleStatusCode()); return dateRangeOK && statusOK; }