List of usage examples for java.util Calendar clone
@Override
public Object clone()
From source file:org.openhab.binding.astro.internal.bus.PlanetPublisher.java
/** * Publishes the item with the value, if the item is a OnOffType and the * value is a calendar, a job is scheduled. */// w ww. ja v a 2s . c om private void publishValue(Item item, Object value, AstroBindingConfig bindingConfig) { if (value == null) { context.getEventPublisher().postUpdate(item.getName(), UnDefType.UNDEF); } else if (value instanceof Calendar) { Calendar calendar = (Calendar) value; if (bindingConfig.getOffset() != 0) { calendar = (Calendar) calendar.clone(); calendar.add(Calendar.MINUTE, bindingConfig.getOffset()); } if (item.getAcceptedDataTypes().contains(DateTimeType.class)) { context.getEventPublisher().postUpdate(item.getName(), new DateTimeType(calendar)); } else if (item.getAcceptedCommandTypes().contains(OnOffType.class)) { context.getJobScheduler().scheduleItem(calendar, item.getName()); } else { logger.warn("Unsupported type for item {}, only DateTimeType and OnOffType supported!", item.getName()); } } else if (value instanceof Number) { if (item.getAcceptedDataTypes().contains(DecimalType.class)) { BigDecimal decimalValue = new BigDecimal(value.toString()).setScale(2, RoundingMode.HALF_UP); context.getEventPublisher().postUpdate(item.getName(), new DecimalType(decimalValue)); } else if (value instanceof Long && item.getAcceptedDataTypes().contains(StringType.class) && "duration".equals(bindingConfig.getProperty())) { // special case, transforming duration to minute:second string context.getEventPublisher().postUpdate(item.getName(), new StringType(durationToString((Long) value))); } else { logger.warn("Unsupported type for item {}, only DecimalType supported!", item.getName()); } } else if (value instanceof String || value instanceof Enum) { if (item.getAcceptedDataTypes().contains(StringType.class)) { if (value instanceof Enum) { String enumValue = WordUtils.capitalizeFully(StringUtils.replace(value.toString(), "_", " ")); context.getEventPublisher().postUpdate(item.getName(), new StringType(enumValue)); } else { context.getEventPublisher().postUpdate(item.getName(), new StringType(value.toString())); } } else { logger.warn("Unsupported type for item {}, only String supported!", item.getName()); } } else { logger.warn("Unsupported value type {}", value.getClass().getSimpleName()); } }
From source file:com.clustercontrol.commons.util.JpaSessionEventListener.java
/** * PUBLIC://w ww .j a v a 2 s .c o m * This event is raised on when using the server/client sessions. * This event is raised before a connection is released into a connection pool. */ public void preReleaseConnection(SessionEvent event) { m_log.debug("Connection release to connection pool"); HinemosEntityManager em = null; em = (HinemosEntityManager) HinemosSessionContext.instance().getProperty(JpaTransactionManager.EM); if (em != null) { setMaxQueueSize(HinemosPropertyUtil .getHinemosPropertyNum("common.db.connectionpool.stats.threshold", Long.valueOf(12)) .intValue()); ServerSession ss = em.unwrap(ServerSession.class); // Hinemos 6.0???????????? // ???????????????????? for (ConnectionPool pool : ss.getConnectionPools().values()) { int used = (pool.getTotalNumberOfConnections() - pool.getConnectionsAvailable().size()); if (m_log.isDebugEnabled()) { m_log.debug("Pool name=" + pool.getName() + ", Used size=" + used + ", Free size=" + pool.getConnectionsAvailable().size()); m_log.debug("Initial=" + pool.getInitialNumberOfConnections() + ":Min=" + pool.getMinNumberOfConnections() + ":Max=" + pool.getMaxNumberOfConnections()); } // Min???? if (used > pool.getMinNumberOfConnections()) { if (m_log.isDebugEnabled()) m_log.info("update min setting:" + pool.getMinNumberOfConnections() + "->" + used + "/max(" + pool.getMaxNumberOfConnections() + ")"); pool.setMinNumberOfConnections(used); } // 1???????"X0"?????????????? // ?????????Min?(?????????) Calendar now = HinemosTime.getCalendarInstance(); Calendar comparetime = (Calendar) now.clone(); // ""???? comparetime.clear(); comparetime.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE), now.get(Calendar.HOUR_OF_DAY), 0, 0); // ???1???????????(???) // comparetime.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE), now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), 0); synchronized (queueUpdateLock) { // ??"X0"??????("X0"?????)??? if (lastAddTime < comparetime.getTimeInMillis()) { if (m_log.isDebugEnabled()) m_log.debug("add queue:used=" + used); queue.addLast(new DBConnectionPoolStats(now.getTimeInMillis(), used)); lastAddTime = now.getTimeInMillis(); // ???? while (queue.size() > maxQueueSize) { if (m_log.isDebugEnabled()) m_log.debug( "remove queue: currentSize=" + queue.size() + ", maxSize=" + maxQueueSize); queue.removeFirst(); } // Min(??)????? int max = used; for (DBConnectionPoolStats stats : queue) { if (stats.getMaxUseCount() > max) max = stats.getMaxUseCount(); } if (m_log.isDebugEnabled()) m_log.debug("max use:" + max); if (pool.getMinNumberOfConnections() > max) { if (m_log.isDebugEnabled()) m_log.info("update min setting(from stats):" + pool.getMinNumberOfConnections() + "->" + used + "/max(" + pool.getMaxNumberOfConnections() + ")"); pool.setMinNumberOfConnections(max); } } // ????????? else if (used > queue.peekLast().getMaxUseCount()) { if (m_log.isDebugEnabled()) m_log.debug("update queue:used=" + used); queue.peekLast().setMaxUseInfo(now.getTimeInMillis(), used); } } } } if (m_log.isTraceEnabled()) { StackTraceElement[] elements = Thread.currentThread().getStackTrace(); for (StackTraceElement element : elements) { m_log.trace("preReleaseConnection():" + element); } } }
From source file:com.joinsystem.goku.common.utils.DateUtil.java
/** * //ww w . j a va 2s. co m * * @param d1 * @param d2 * @return */ public static int diffDays(Calendar d1, Calendar d2) { if (d1.after(d2)) { java.util.Calendar swap = d1; d1 = d2; d2 = swap; } int days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR); int y2 = d2.get(Calendar.YEAR); if (d1.get(Calendar.YEAR) != y2) { d1 = (Calendar) d1.clone(); do { days += d1.getActualMaximum(Calendar.DAY_OF_YEAR);// d1.add(Calendar.YEAR, 1); } while (d1.get(Calendar.YEAR) != y2); } return days; }
From source file:org.sakaiproject.tool.summarycalendar.ui.EventSummary.java
private boolean isSameDay(long startMs, long endMs) { Calendar s = Calendar.getInstance(); Calendar e = (Calendar) s.clone(); s.setTimeInMillis(startMs);/*from w w w . j a v a 2s . c o m*/ e.setTimeInMillis(endMs); return (s.get(Calendar.ERA) == e.get(Calendar.ERA) && s.get(Calendar.YEAR) == e.get(Calendar.YEAR) && s.get(Calendar.DAY_OF_YEAR) == e.get(Calendar.DAY_OF_YEAR)); }
From source file:jp.dip.komusubi.botter.gae.module.jal5971.FlightStatusScraper.java
protected String buildUrl(String baseUrl) { String queryFragments = null; Calendar current = DateUtils.toCalendar(dateResolver.resolve()); Calendar requested = DateUtils.toCalendar(this.date); Calendar tomorrow = (Calendar) current.clone(); tomorrow.add(Calendar.DAY_OF_MONTH, 1); Calendar yesterday = (Calendar) current.clone(); yesterday.add(Calendar.DAY_OF_MONTH, -1); if (DateUtils.truncatedEquals(requested, yesterday, Calendar.DAY_OF_MONTH)) { queryFragments = "&DATEFLG=1"; // ? } else if (DateUtils.truncatedEquals(requested, tomorrow, Calendar.DAY_OF_MONTH)) { queryFragments = "&DATEFLG=2"; // } else if (DateUtils.truncatedEquals(requested, current, Calendar.DAY_OF_MONTH)) { queryFragments = ""; }/* ww w. j av a 2 s . co m*/ if (queryFragments == null) throw new IllegalStateException("requested date: " + DateFormatUtils.format(requested, "yyyy/MM/dd") + " was over rage, current date is " + DateFormatUtils.format(current, "yyyy/MM/dd")); StringBuilder builder = new StringBuilder(baseUrl); builder.append("?DPORT=").append(route.getDeparture().getCode()).append("&APORT=") .append(route.getArrival().getCode()).append(queryFragments); return builder.toString(); }
From source file:org.psidnell.omnifocus.expr.ExpressionFunctionsTest.java
private Calendar clone(Calendar cal) { return (Calendar) cal.clone(); }
From source file:org.eclipse.smarthome.binding.astro.internal.calc.SunCalc.java
/** * Adds the specified days to the calendar. *///from w w w .j av a 2s . com private Calendar addDays(Calendar calendar, int days) { Calendar cal = (Calendar) calendar.clone(); cal.add(Calendar.DAY_OF_MONTH, days); return cal; }
From source file:com.example.ingridstoen.alarme.calandar.java
public String getNextWeekOfDay(int weekOfDay) { DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); Calendar today = Calendar.getInstance(); int dayOfWeek = today.get(Calendar.DAY_OF_WEEK); int daysUntilNextWeekOfDay = weekOfDay - dayOfWeek; Calendar nextWeekOfDay = (Calendar) today.clone(); nextWeekOfDay.add(Calendar.DAY_OF_WEEK, daysUntilNextWeekOfDay); nextWeekOfDay.add(Calendar.DAY_OF_WEEK, 7); nextWeekOfDay.set(Calendar.HOUR_OF_DAY, 0); Date nextWeekOfDayDateFormat = nextWeekOfDay.getTime(); String dateString = dateFormat.format(nextWeekOfDayDateFormat); return dateString; }
From source file:de.lemo.apps.application.DateWorkerImpl.java
public int daysBetween(final Calendar startDate, final Calendar endDate) { // TODO a loop seems inefficient for this. Maybe use joda time, it has a `daysBetween` method. // Is the the result correct? - We get '1 day' even if the dates are only seconds apart. final Calendar date = (Calendar) startDate.clone(); int daysBetween = 0; while (date.before(endDate)) { date.add(Calendar.DAY_OF_MONTH, 1); daysBetween++;/*from w ww . j a v a 2s .c o m*/ } return daysBetween; }
From source file:edu.duke.cabig.c3pr.domain.scheduler.runtime.job.ScheduledNotificationJob.java
private List<DataAuditEvent> getAuditHistory(AuditHistoryRepository auditHistoryRepository, PlannedNotification plannedNotification) { DataAuditEventQuery dataAuditEventQuery = new DataAuditEventQuery(); Calendar now = Calendar.getInstance(); Calendar prev = (Calendar) now.clone(); if (plannedNotification.getFrequency().equals(NotificationFrequencyEnum.WEEKLY)) { prev.add(Calendar.DATE, -7); }/*from ww w . ja v a2 s .co m*/ if (plannedNotification.getFrequency().equals(NotificationFrequencyEnum.MONTHLY)) { prev.add(Calendar.MONTH, -1); } if (plannedNotification.getFrequency().equals(NotificationFrequencyEnum.ANNUAL)) { prev.add(Calendar.YEAR, -1); } dataAuditEventQuery.filterByClassName(StudySubject.class.getName()); dataAuditEventQuery.filterByEndDateBefore(now.getTime()); dataAuditEventQuery.filterByStartDateAfter(prev.getTime()); //where the status has changed to REGISTERED dataAuditEventQuery.filterByValue("regWorkflowStatus", null, RegistrationWorkFlowStatus.ON_STUDY.toString()); final List<DataAuditEvent> dataAuditEvents = auditHistoryRepository .findDataAuditEvents(dataAuditEventQuery); return dataAuditEvents; }