本文整理汇总了Java中org.joda.time.base.AbstractInstant类的典型用法代码示例。如果您正苦于以下问题:Java AbstractInstant类的具体用法?Java AbstractInstant怎么用?Java AbstractInstant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractInstant类属于org.joda.time.base包,在下文中一共展示了AbstractInstant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeTimer
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
/**
* helper function to create the timer
* @param instant the point in time when the code should be executed
* @param closure string for job id
* @param dataMap job data map, preconfigured with arguments
* @return
*/
private static Timer makeTimer(AbstractInstant instant, String closure, JobDataMap dataMap) {
JobKey jobKey = new JobKey(instant.toString() + ": " + closure.toString());
Trigger trigger = newTrigger().startAt(instant.toDate()).build();
Timer timer = new TimerImpl(jobKey, trigger.getKey(), instant);
dataMap.put("timer", timer);
try {
JobDetail job = newJob(TimerExecutionJob.class)
.withIdentity(jobKey)
.usingJobData(dataMap)
.build();
TimerImpl.scheduler.scheduleJob(job, trigger);
logger.debug("Scheduled code for execution at {}", instant.toString());
return timer;
} catch(SchedulerException e) {
logger.error("Failed to schedule code for execution.", e);
return null;
}
}
示例2: historicState
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
/**
* Retrieves the state of a given <code>item</code> to a certain point in time through a {@link PersistenceService} identified
* by the <code>serviceName</code>.
*
* @param item the item to retrieve the state for
* @param the point in time for which the state should be retrieved
* @param serviceName the name of the {@link PersistenceService} to use
* @return the item state at the given point in time
*/
static public HistoricItem historicState(Item item, AbstractInstant timestamp, String serviceName) {
PersistenceService service = services.get(serviceName);
if (service instanceof QueryablePersistenceService) {
QueryablePersistenceService qService = (QueryablePersistenceService) service;
FilterCriteria filter = new FilterCriteria();
filter.setEndDate(timestamp.toDate());
filter.setItemName(item.getName());
filter.setPageSize(1);
filter.setOrdering(Ordering.DESCENDING);
Iterable<HistoricItem> result = qService.query(filter);
if(result.iterator().hasNext()) {
return result.iterator().next();
} else {
return null;
}
} else {
logger.warn("There is no queryable persistence service registered with the name '{}'", serviceName);
return null;
}
}
示例3: changedSince
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
/**
* Checks if the state of a given <code>item</code> has changed since a certain point in time.
* The {@link PersistenceService} identified by the <code>serviceName</code> is used.
*
* @param item the item to check for state changes
* @param the point in time to start the check
* @param serviceName the name of the {@link PersistenceService} to use
* @return true, if item state had changed
*/
static public Boolean changedSince(Item item, AbstractInstant timestamp, String serviceName) {
Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceName);
Iterator<HistoricItem> it = result.iterator();
HistoricItem itemThen = historicState(item, timestamp);
if(itemThen == null) {
// Can't get the state at the start time
// If we've got results more recent that this, it must have changed
return(it.hasNext());
}
State state = itemThen.getState();
while(it.hasNext()) {
HistoricItem hItem = it.next();
if(state!=null && !hItem.getState().equals(state)) {
return true;
}
state = hItem.getState();
}
return false;
}
示例4: sumSince
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
/**
* Gets the sum of the state of a given <code>item</code> since a certain point in time.
* The {@link PersistenceService} identified by the <code>serviceName</code> is used.
*
* @param item the item to get the average state value for
* @param the point in time to start the check
* @param serviceName the name of the {@link PersistenceService} to use
* @return the sum state value since the given point in time
*/
static public DecimalType sumSince(Item item, AbstractInstant timestamp, String serviceName) {
Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceName);
Iterator<HistoricItem> it = result.iterator();
double sum = 0;
while(it.hasNext()) {
State state = it.next().getState();
if (state instanceof DecimalType) {
sum += ((DecimalType) state).doubleValue();
}
}
return new DecimalType(sum);
}
示例5: main
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
public static void main(String[] args) {
System.out.println("-----------------------------------------------");
System.out.println("-----------AbstractInstant---------------------");
Class cls = AbstractInstant.class;
System.out.println("-----------ReadableDateTime--------------------");
cls = ReadableDateTime.class;
System.out.println("-----------AbstractDateTime--------------------");
cls = AbstractDateTime.class;
System.out.println("-----------DateTime----------------------------");
cls = DateTime.class;
System.out.println("-----------DateTimeZone------------------------");
cls = DateTimeZone.class;
System.out.println("-----------new DateTime()----------------------");
DateTime dt = new DateTime();
System.out.println("-----------new DateTime(ReadableInstant)-------");
dt = new DateTime(dt);
System.out.println("-----------new DateTime(Long)------------------");
dt = new DateTime(new Long(0));
System.out.println("-----------------------------------------------");
}
示例6: testGetInstantChronology_RI
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
public void testGetInstantChronology_RI() {
DateTime dt = new DateTime(123L, BuddhistChronology.getInstance());
assertEquals(BuddhistChronology.getInstance(), DateTimeUtils.getInstantChronology(dt));
Instant i = new Instant(123L);
assertEquals(ISOChronology.getInstanceUTC(), DateTimeUtils.getInstantChronology(i));
AbstractInstant ai = new AbstractInstant() {
public long getMillis() {
return 0L;
}
public Chronology getChronology() {
return null; // testing for this
}
};
assertEquals(ISOChronology.getInstance(), DateTimeUtils.getInstantChronology(ai));
assertEquals(ISOChronology.getInstance(), DateTimeUtils.getInstantChronology(null));
}
示例7: getPreviousValue
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
protected HistoricItem getPreviousValue(Item theItem) {
DateTime now = new DateTime();
AbstractInstant earlier = now.minusHours(6);
if (persistenceService == null) {
return PersistenceExtensions.historicState(theItem, earlier);
} else {
return PersistenceExtensions.historicState(theItem, earlier, persistenceService);
}
}
示例8: reschedule
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
public boolean reschedule(AbstractInstant newTime) {
try {
Trigger trigger = newTrigger().startAt(newTime.toDate()).build();
scheduler.rescheduleJob(triggerKey, trigger);
this.triggerKey = trigger.getKey();
this.cancelled = false;
this.terminated = false;
return true;
} catch (SchedulerException e) {
logger.warn("An error occured while rescheduling the job '{}': {}", new String[] { jobKey.toString(), e.getMessage() });
return false;
}
}
示例9: makeTimer
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
private static Timer makeTimer(AbstractInstant instant, String closure, JobDataMap dataMap) {
JobKey jobKey = new JobKey(instant.toString() + ": " + closure.toString());
Trigger trigger = newTrigger().startAt(instant.toDate()).build();
Timer timer = new Timer(jobKey, trigger.getKey(), instant);
dataMap.put("timer", timer);
try {
JobDetail job = newJob(TimerExecutionJob.class).withIdentity(jobKey).usingJobData(dataMap).build();
Timer.scheduler.scheduleJob(job, trigger);
logger.debug("Scheduled code for execution at {}", instant.toString());
return timer;
} catch (SchedulerException e) {
logger.error("Failed to schedule code for execution.", e);
return null;
}
}
示例10: reschedule
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
public boolean reschedule(AbstractInstant newTime) {
try {
Trigger trigger = newTrigger().startAt(newTime.toDate()).build();
scheduler.rescheduleJob(triggerKey, trigger);
this.triggerKey = trigger.getKey();
this.cancelled = false;
this.terminated = false;
return true;
} catch (SchedulerException e) {
logger.warn("An error occured while rescheduling the job '{}': {}", new String[] { jobKey.toString(), e.getMessage() });
return false;
}
}
示例11: getAllStatesSince
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
static private Iterable<HistoricItem> getAllStatesSince(Item item, AbstractInstant timestamp, String serviceName) {
PersistenceService service = services.get(serviceName);
if (service instanceof QueryablePersistenceService) {
QueryablePersistenceService qService = (QueryablePersistenceService) service;
FilterCriteria filter = new FilterCriteria();
filter.setBeginDate(timestamp.toDate());
filter.setItemName(item.getName());
filter.setOrdering(Ordering.ASCENDING);
return qService.query(filter);
} else {
logger.warn("There is no queryable persistence service registered with the name '{}'", serviceName);
return Collections.emptySet();
}
}
示例12: format
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
@Override
public String format(final AbstractInstant target, String pattern) {
try {
return DateTimeFormat.forPattern(pattern).withLocale(locale).print(target);
} catch (final Exception e) {
throw new TemplateProcessingException(
"Error formatting Joda DateTime with pattern '" + pattern + "' for locale " + this.locale, e);
}
}
示例13: extractLastApprovedOrRejectDate
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
DateTime extractLastApprovedOrRejectDate(List<StatusChange> statusChangeHistory) {
return statusChangeHistory.stream()
.filter(statusChange -> asList(Status.APPROVED, Status.REJECTED).contains(statusChange.getTo()))
.map(StatusChange::getChangedOn)
.max(AbstractInstant::compareTo)
.orElseGet(() -> null);
}
示例14: extractFirstSubmissionDate
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
DateTime extractFirstSubmissionDate(List<StatusChange> statusChangeHistory) {
return statusChangeHistory.stream()
.filter(statusChange -> Status.SUBMITTED.equals(statusChange.getTo()))
.map(StatusChange::getChangedOn)
.min(AbstractInstant::compareTo)
.orElseGet(() -> null);
}
示例15: getPreviousValue
import org.joda.time.base.AbstractInstant; //导入依赖的package包/类
protected HistoricItem getPreviousValue(Item theItem) {
DateTime now = new DateTime();
AbstractInstant earlier = now.minusHours(6);
if (persistenceService == null) {
return PersistenceExtensions.historicState(theItem, earlier);
} else {
return PersistenceExtensions.historicState(theItem, earlier, persistenceService);
}
}