Java 类org.joda.time.base.AbstractInstant 实例源码

项目:openhab-hdl    文件:ScriptExecution.java   
/**
 * 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;
    }       
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * 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;
    }
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * 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;
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * 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);
}
项目:astor    文件:ClassLoadTest.java   
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("-----------------------------------------------");
}
项目:astor    文件:TestDateTimeUtils.java   
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));
}
项目:astor    文件:ClassLoadTest.java   
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("-----------------------------------------------");
}
项目:astor    文件:TestDateTimeUtils.java   
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));
}
项目:versemem-android    文件:ClassLoadTest.java   
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("-----------------------------------------------");
}
项目:versemem-android    文件:TestDateTimeUtils.java   
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));
}
项目:openhab-hdl    文件:SagerCasterBinding.java   
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);           
    }
}
项目:openhab-hdl    文件:TimerImpl.java   
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;
    }
}
项目:openhab-hdl    文件:Openhab.java   
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;
    }
}
项目:openhab-hdl    文件:Timer.java   
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;
    }
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * Retrieves the state of a given <code>item</code> to a certain point in time through the default persistence service. 
 * 
 * @param item the item to retrieve the state for
 * @param the point in time for which the state should be retrieved 
 * @return the item state at the given point in time
 */
static public HistoricItem historicState(Item item, AbstractInstant timestamp) {
    if(isDefaultServiceAvailable()) {
        return historicState(item, timestamp, defaultService);
    } else {
        return null;
    }
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
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();
    }
}
项目:thymeleaf-joda    文件:JodaImpl.java   
@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);
    }
}
项目:mica2    文件:CsvReportGenerator.java   
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);
}
项目:mica2    文件:CsvReportGenerator.java   
DateTime extractFirstSubmissionDate(List<StatusChange> statusChangeHistory) {
  return statusChangeHistory.stream()
    .filter(statusChange -> Status.SUBMITTED.equals(statusChange.getTo()))
    .map(StatusChange::getChangedOn)
    .min(AbstractInstant::compareTo)
    .orElseGet(() -> null);
}
项目:openhab1-addons    文件:SagerCasterBinding.java   
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);
    }
}
项目:Sound.je    文件:AuditedEntity.java   
/**
 * Sets last modified date.
 *
 * @param lastModifiedDate the last modified date
 */
public void setLastModifiedDate(final DateTime lastModifiedDate) {
    this.lastModifiedDate = Optional.ofNullable(lastModifiedDate)
            .map(AbstractInstant::toDate)
            .orElse(null);
}
项目:openhab-hdl    文件:TimerImpl.java   
public TimerImpl(JobKey jobKey, TriggerKey triggerKey, AbstractInstant startTime) {
    this.jobKey = jobKey;
    this.triggerKey = triggerKey;
    this.startTime = startTime;
}
项目:openhab-hdl    文件:Openhab.java   
public static Timer createTimer(AbstractInstant instant, Runnable closure) {
    JobDataMap dataMap = new JobDataMap();
    dataMap.put("procedure", closure);
    return makeTimer(instant, closure.toString(), dataMap);
}
项目:openhab-hdl    文件:Timer.java   
public Timer(JobKey jobKey, TriggerKey triggerKey, AbstractInstant startTime) {
    this.jobKey = jobKey;
    this.triggerKey = triggerKey;
    this.startTime = startTime;
}
项目:oap    文件:Timestamp.java   
public static Stream<String> timestampsBeforeNow( DateTime since ) {
    return Stream.of( since, AbstractInstant::isBeforeNow, t -> t.plusMinutes( 60 / BUCKETS_PER_HOUR ) )
        .map( Timestamp::format );
}
项目:thymeleaf-joda    文件:JodaImpl.java   
@Override
public long timestamp(final AbstractInstant target) {
    return target.getMillis();
}
项目:thymeleaf-joda    文件:JodaImpl.java   
@Override
public boolean before(final AbstractInstant date1, final AbstractInstant date2) {
    return date1.isBefore(date2);
}
项目:thymeleaf-joda    文件:JodaImpl.java   
@Override
public boolean after(final AbstractInstant date1, final AbstractInstant date2) {
    return date1.isAfter(date2);
}
项目:thymeleaf-joda    文件:JodaImpl.java   
@Override
public boolean equals(final AbstractInstant date1, final AbstractInstant date2) {
    return date1.equals(date2);
}
项目:openhab-hdl    文件:ScriptExecution.java   
/**
 * Schedules a block of code (with argument) for later execution
 * 
 * @param instant the point in time when the code should be executed
 * @param arg1 the argument to pass to the code block
 * @param closure the code block to execute
 * 
 * @return a handle to the created timer, so that it can be canceled or rescheduled
 * @throws ScriptExecutionException if an error occurs during the execution
 */
public static Timer createTimerWithArgument(AbstractInstant instant, Object arg1, Procedure1<Object> closure) {
    JobDataMap dataMap = new JobDataMap();
    dataMap.put("procedure1", closure);
    dataMap.put("argument1", arg1);
    return makeTimer(instant, closure.toString(), dataMap);
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * Checks if the state of a given <code>item</code> has changed since a certain point in time. 
 * The default persistence service is used. 
 * 
 * @param item the item to check for state changes
 * @param the point in time to start the check 
 * @return true, if item state had changed
 */
static public Boolean changedSince(Item item, AbstractInstant timestamp) {
    if(isDefaultServiceAvailable()) {
        return changedSince(item, timestamp, defaultService);
    } else {
        return null;
    }
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * Checks if the state of a given <code>item</code> has been updated since a certain point in time. 
 * The default persistence service is used. 
 * 
 * @param item the item to check for state updates
 * @param the point in time to start the check 
 * @return true, if item state was updated
 */
static public Boolean updatedSince(Item item, AbstractInstant timestamp) {
    if(isDefaultServiceAvailable()) {
        return updatedSince(item, timestamp, defaultService);
    } else {
        return null;
    }
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * 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 was updated
 */
static public Boolean updatedSince(Item item, AbstractInstant timestamp, String serviceName) {
    Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceName);
    if(result.iterator().hasNext()) {
        return true;
    } else {
        return false;
    }
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * Gets the historic item with the maximum value of the state of a given <code>item</code> since
 * a certain point in time. 
 * The default persistence service is used. 
 * 
 * @param item the item to get the maximum state value for
 * @param the point in time to start the check 
 * @return a historic item with the maximum state value since the given point in time
 */
static public HistoricItem maximumSince(Item item, AbstractInstant timestamp) {
    if(isDefaultServiceAvailable()) {
        return maximumSince(item, timestamp, defaultService);
    } else {
        return null;
    }
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * Gets the historic item with the minimum value of the state of a given <code>item</code> since
 * a certain point in time. 
 * The default persistence service is used. 
 * 
 * @param item the item to get the minimum state value for
 * @param the point in time to start the check 
 * @return the historic item with the minimum state value since the given point in time
 */
static public HistoricItem minimumSince(Item item, AbstractInstant timestamp) {
    if(isDefaultServiceAvailable()) {
        return minimumSince(item, timestamp, defaultService);
    } else {
        return null;
    }
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * Gets the average value of the state of a given <code>item</code> since a certain point in time. 
 * The default persistence service is used. 
 * 
 * @param item the item to get the average state value for
 * @param the point in time to start the check 
 * @return the average state value since the given point in time
 */
static public DecimalType averageSince(Item item, AbstractInstant timestamp) {
    if(isDefaultServiceAvailable()) {
        return averageSince(item, timestamp, defaultService);
    } else {
        return null;
    }
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * Gets the variance value of the state of a given <code>item</code> since a certain point in time. 
 * The default persistence service is used. 
 * 
 * @param item the item to get the average state value for
 * @param the point in time to start the check 
 * @return the variance of the value since the given point in time
 */
static public DecimalType varianceSince(Item item, AbstractInstant timestamp) {
    if(isDefaultServiceAvailable()) {
        return varianceSince(item, timestamp, defaultService);
    } else {
        return null;
    }
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * Gets the standard deviation value of the state of a given <code>item</code> since a certain point in time. 
 * The default persistence service is used. 
 * 
 * @param item the item to get the average state value for
 * @param the point in time to start the check 
 * @return the standard deviation of the value since the given point in time
 */
static public DecimalType deviationSince(Item item, AbstractInstant timestamp) {
    if(isDefaultServiceAvailable()) {
        return deviationSince(item, timestamp, defaultService);
    } else {
        return null;
    }
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * Gets the standard deviation value 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 standard deviation of the value since the given point in time
 */
static public DecimalType deviationSince(Item item, AbstractInstant timestamp, String serviceName) {
    DecimalType variance = varianceSince(item, timestamp, serviceName);
    double deviation = Math.sqrt(variance.doubleValue());

        return new DecimalType(deviation);
}
项目:openhab-hdl    文件:PersistenceExtensions.java   
/**
 * Gets the sum of the state of a given <code>item</code> since a certain point in time. 
 * The default persistence service is used. 
 * 
 * @param item the item to get the average state value for
 * @param the point in time to start the check 
 * @return the average state value since the given point in time
 */
static public DecimalType sumSince(Item item, AbstractInstant timestamp) {
    if(isDefaultServiceAvailable()) {
        return sumSince(item, timestamp, defaultService);
    } else {
        return null;
    }
}