org.joda.time.base.AbstractInstant Java Examples

The following examples show how to use org.joda.time.base.AbstractInstant. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private static Iterable<HistoricItem> getAllStatesSince(Item item, AbstractInstant timestamp, String serviceId) {
    PersistenceService service = getService(serviceId);
    if (service instanceof QueryablePersistenceService) {
        QueryablePersistenceService qService = (QueryablePersistenceService) service;
        FilterCriteria filter = new FilterCriteria();
        filter.setBeginDate(
                ZonedDateTime.ofInstant(timestamp.toDate().toInstant(), timeZoneProvider.getTimeZone()));
        filter.setItemName(item.getName());
        filter.setOrdering(Ordering.ASCENDING);
        return qService.query(filter);
    } else {
        LoggerFactory.getLogger(PersistenceExtensions.class)
                .warn("There is no queryable persistence service registered with the id '{}'", serviceId);
        return Collections.emptySet();
    }
}
 
Example #2
Source File: TimerImpl.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean reschedule(AbstractInstant newTime) {
    try {
        Trigger trigger = newTrigger().startAt(newTime.toDate()).build();
        Date nextTriggerTime = scheduler.rescheduleJob(triggerKey, trigger);
        if (nextTriggerTime == null) {
            logger.debug("Scheduling a new job job '{}' because the original has already run", jobKey.toString());
            JobDetail job = newJob(TimerExecutionJob.class).withIdentity(jobKey).usingJobData(dataMap).build();
            TimerImpl.scheduler.scheduleJob(job, trigger);
        }
        this.triggerKey = trigger.getKey();
        this.cancelled = false;
        this.terminated = false;
        return true;
    } catch (SchedulerException e) {
        logger.warn("An error occurred while rescheduling the job '{}': {}", jobKey.toString(), e.getMessage());
        return false;
    }
}
 
Example #3
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Query for the last update time of a given <code>item</code>.
 *
 * @param item the item for which the last update time is to be returned
 * @param serviceId the name of the {@link PersistenceService} to use
 * @return last time <code>item</code> was updated, or <code>null</code> if there are no previously
 *         persisted updates or if persistence service given by <code>serviceId</code> does not refer to an
 *         available {@link QueryablePersistenceService}
 */
public static AbstractInstant lastUpdate(Item item, String serviceId) {
    PersistenceService service = getService(serviceId);
    if (service instanceof QueryablePersistenceService) {
        QueryablePersistenceService qService = (QueryablePersistenceService) service;
        FilterCriteria filter = new FilterCriteria();
        filter.setItemName(item.getName());
        filter.setOrdering(Ordering.DESCENDING);
        filter.setPageSize(1);
        Iterable<HistoricItem> result = qService.query(filter);
        if (result.iterator().hasNext()) {
            return new DateTime(result.iterator().next().getTimestamp());
        } else {
            return null;
        }
    } else {
        LoggerFactory.getLogger(PersistenceExtensions.class)
                .warn("There is no queryable persistence service registered with the id '{}'", serviceId);
        return null;
    }
}
 
Example #4
Source File: ClassLoadTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
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("-----------------------------------------------");
}
 
Example #5
Source File: TestDateTimeUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
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));
}
 
Example #6
Source File: ClassLoadTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
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("-----------------------------------------------");
}
 
Example #7
Source File: TestDateTimeUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
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));
}
 
Example #8
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Retrieves the historic item for a given <code>item</code> at a certain point in time through a
 * {@link PersistenceService} identified by the <code>serviceId</code>.
 *
 * @param item the item for which to retrieve the historic item
 * @param timestamp the point in time for which the historic item should be retrieved
 * @param serviceId the name of the {@link PersistenceService} to use
 * @return the historic item at the given point in time, or <code>null</code> if no historic item could be found or
 *         if the provided <code>serviceId</code> does not refer to an available
 *         {@link QueryablePersistenceService}
 */
public static HistoricItem historicState(Item item, AbstractInstant timestamp, String serviceId) {
    PersistenceService service = getService(serviceId);
    if (service instanceof QueryablePersistenceService) {
        QueryablePersistenceService qService = (QueryablePersistenceService) service;
        FilterCriteria filter = new FilterCriteria();
        filter.setEndDate(ZonedDateTime.ofInstant(timestamp.toDate().toInstant(), timeZoneProvider.getTimeZone()));
        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 {
        LoggerFactory.getLogger(PersistenceExtensions.class)
                .warn("There is no queryable persistence service registered with the id '{}'", serviceId);
        return null;
    }
}
 
Example #9
Source File: ScriptExecution.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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) {

    Logger logger = LoggerFactory.getLogger(ScriptExecution.class);
    JobKey jobKey = new JobKey(instant.toString() + ": " + closure.toString());
    Trigger trigger = newTrigger().startAt(instant.toDate()).build();
    Timer timer = new TimerImpl(jobKey, trigger.getKey(), dataMap, instant);
    try {
        JobDetail job = newJob(TimerExecutionJob.class).withIdentity(jobKey).usingJobData(dataMap).build();
        if (TimerImpl.scheduler.checkExists(job.getKey())) {
            TimerImpl.scheduler.deleteJob(job.getKey());
            logger.debug("Deleted existing Job {}", job.getKey().toString());
        }
        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;
    }
}
 
Example #10
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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>serviceId</code> is used.
 *
 * @param item the item to check for state changes
 * @param timestamp the point in time to start the check
 * @param serviceId the name of the {@link PersistenceService} to use
 * @return <code>true</code> if item state has changed, or <code>false</code> if it hasn't or if the given
 *         <code>serviceId</code> does not refer to an available {@link QueryablePersistenceService}
 */
public static Boolean changedSince(Item item, AbstractInstant timestamp, String serviceId) {
    Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceId);
    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;
}
 
Example #11
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Gets the evolution rate of the state of a given <code>item</code> since a certain point in time.
 * The {@link PersistenceService} identified by the <code>serviceId</code> is used.
 *
 * @param item the item to get the evolution rate value for
 * @param timestamp the point in time from which to compute the evolution rate
 * @param serviceId the name of the {@link PersistenceService} to use
 * @return the evolution rate in percent (positive and negative) between now and then, or <code>null</code> if
 *         the persistence service given by serviceId is not available or is not a
 *         {@link QueryablePersistenceService}, or if there is no persisted state for the given
 *         <code>item</code> at the given <code>timestamp</code> using the persistence service given by
 *         <code>serviceId</code>, or if there is a state but it is zero (which would cause a divide-by-zero
 *         error)
 */
public static DecimalType evolutionRate(Item item, AbstractInstant timestamp, String serviceId) {
    HistoricItem itemThen = historicState(item, timestamp, serviceId);
    if (itemThen != null) {
        DecimalType valueThen = (DecimalType) itemThen.getState();
        DecimalType valueNow = item.getStateAs(DecimalType.class);

        if ((valueThen != null) && (valueThen.toBigDecimal().compareTo(BigDecimal.ZERO) != 0)
                && (valueNow != null)) {
            // ((now - then) / then) * 100
            return new DecimalType(valueNow.toBigDecimal().subtract(valueThen.toBigDecimal())
                    .divide(valueThen.toBigDecimal(), MathContext.DECIMAL64).movePointRight(2));
        }
    }
    return null;
}
 
Example #12
Source File: TimerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public TimerImpl(JobKey jobKey, TriggerKey triggerKey, JobDataMap dataMap, AbstractInstant startTime) {
    this.jobKey = jobKey;
    this.triggerKey = triggerKey;
    this.dataMap = dataMap;
    this.startTime = startTime;
    dataMap.put("timer", this);
}
 
Example #13
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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>serviceId</code> is used.
 *
 * @param item the item for which we will sum its persisted state values since <code>timestamp</code>
 * @param timestamp the point in time from which to start the summation
 * @param serviceId the name of the {@link PersistenceService} to use
 * @return the sum of the state values since the given point in time, or {@link DecimalType.ZERO} if no historic
 *         states could be found for the <code>item</code> or if <code>serviceId</code> does no refer to a
 *         {@link QueryablePersistenceService}
 */
public static DecimalType sumSince(Item item, AbstractInstant timestamp, String serviceId) {
    Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceId);
    Iterator<HistoricItem> it = result.iterator();

    BigDecimal sum = BigDecimal.ZERO;
    while (it.hasNext()) {
        State state = it.next().getState();
        if (state instanceof DecimalType) {
            sum = sum.add(((DecimalType) state).toBigDecimal());
        }
    }

    return new DecimalType(sum);
}
 
Example #14
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Gets the difference value of the state of a given <code>item</code> since a certain point in time.
 * The {@link PersistenceService} identified by the <code>serviceId</code> is used.
 *
 * @param item the item to get the average state value for
 * @param timestamp the point in time from which to compute the delta
 * @param serviceId the name of the {@link PersistenceService} to use
 * @return the difference between now and then, or <code>null</code> if the given serviceId does not refer to an
 *         available {@link QueryablePersistenceService}, or if there is no persisted state for the given
 *         <code>item</code> at the given <code>timestamp</code> using the persistence service named
 *         <code>serviceId</code>
 */
public static DecimalType deltaSince(Item item, AbstractInstant timestamp, String serviceId) {
    HistoricItem itemThen = historicState(item, timestamp, serviceId);
    if (itemThen != null) {
        DecimalType valueThen = (DecimalType) itemThen.getState();
        DecimalType valueNow = item.getStateAs(DecimalType.class);

        if ((valueThen != null) && (valueNow != null)) {
            return new DecimalType(valueNow.toBigDecimal().subtract(valueThen.toBigDecimal()));
        }
    }
    return null;
}
 
Example #15
Source File: TaskConfiguration.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public Date getDate(final String key, final Date defaultValue) {
  return Optional.ofNullable(key)
      .map(this::getString)
      .map(DateTime::new)
      .map(AbstractInstant::toDate)
      .orElse(defaultValue);
}
 
Example #16
Source File: SagerCasterBinding.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #17
Source File: CalciteUtils.java    From beam with Apache License 2.0 5 votes vote down vote up
/**
 * SQL-Java type mapping, with specified Beam rules: <br>
 * 1. redirect {@link AbstractInstant} to {@link Date} so Calcite can recognize it.
 *
 * @param rawType
 * @return
 */
public static RelDataType sqlTypeWithAutoCast(RelDataTypeFactory typeFactory, Type rawType) {
  // For Joda time types, return SQL type for java.util.Date.
  if (rawType instanceof Class && AbstractInstant.class.isAssignableFrom((Class<?>) rawType)) {
    return typeFactory.createJavaType(Date.class);
  } else if (rawType instanceof Class && ByteString.class.isAssignableFrom((Class<?>) rawType)) {
    return typeFactory.createJavaType(byte[].class);
  }
  return typeFactory.createJavaType((Class) rawType);
}
 
Example #18
Source File: RowUtils.java    From beam with Apache License 2.0 4 votes vote down vote up
Instant processDateTime(
RowPosition rowPosition, AbstractInstant instant, RowFieldMatcher matcher);
 
Example #19
Source File: RowUtils.java    From beam with Apache License 2.0 4 votes vote down vote up
@Override
public Instant processDateTime(
    RowPosition rowPosition, AbstractInstant value, RowFieldMatcher matcher) {
  AbstractInstant instantValue = overrideOrReturn(rowPosition, value);
  return (instantValue != null) ? instantValue.toInstant() : null;
}
 
Example #20
Source File: RowUtils.java    From beam with Apache License 2.0 4 votes vote down vote up
public Object match(
    RowCases cases, FieldType fieldType, RowPosition rowPosition, Object value) {
  Object processedValue = null;
  switch (fieldType.getTypeName()) {
    case ARRAY:
      processedValue =
          cases.processArray(
              rowPosition,
              fieldType.getCollectionElementType(),
              (Collection<Object>) value,
              this);
      break;
    case ITERABLE:
      processedValue =
          cases.processIterable(
              rowPosition,
              fieldType.getCollectionElementType(),
              (Iterable<Object>) value,
              this);
      break;
    case MAP:
      processedValue =
          cases.processMap(
              rowPosition,
              fieldType.getMapKeyType(),
              fieldType.getMapValueType(),
              (Map<Object, Object>) value,
              this);
      break;
    case ROW:
      processedValue =
          cases.processRow(rowPosition, fieldType.getRowSchema(), (Row) value, this);
      break;
    case LOGICAL_TYPE:
      LogicalType logicalType = fieldType.getLogicalType();
      processedValue = cases.processLogicalType(rowPosition, logicalType, value, this);
      break;
    case DATETIME:
      processedValue = cases.processDateTime(rowPosition, (AbstractInstant) value, this);
      break;
    case BYTE:
      processedValue = cases.processByte(rowPosition, (Byte) value, this);
      break;
    case BYTES:
      processedValue = cases.processBytes(rowPosition, (byte[]) value, this);
      break;
    case INT16:
      processedValue = cases.processInt16(rowPosition, (Short) value, this);
      break;
    case INT32:
      processedValue = cases.processInt32(rowPosition, (Integer) value, this);
      break;
    case INT64:
      processedValue = cases.processInt64(rowPosition, (Long) value, this);
      break;
    case DECIMAL:
      processedValue = cases.processDecimal(rowPosition, (BigDecimal) value, this);
      break;
    case FLOAT:
      processedValue = cases.processFloat(rowPosition, (Float) value, this);
      break;
    case DOUBLE:
      processedValue = cases.processDouble(rowPosition, (Double) value, this);
      break;
    case STRING:
      processedValue = cases.processString(rowPosition, (String) value, this);
      break;
    case BOOLEAN:
      processedValue = cases.processBoolean(rowPosition, (Boolean) value, this);
      break;
    default:
      // Shouldn't actually get here, but we need this case to satisfy linters.
      throw new IllegalArgumentException(
          String.format(
              "Not a primitive type for field name %s: %s", rowPosition.descriptor, fieldType));
  }
  if (processedValue == null) {
    if (!fieldType.getNullable()) {
      throw new IllegalArgumentException(
          String.format("%s is not nullable in  field %s", fieldType, rowPosition.descriptor));
    }
  }
  return processedValue;
}
 
Example #21
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * 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>serviceId</code> is used.
 *
 * @param item the item to check for state changes
 * @param timestamp the point in time to start the check
 * @param serviceId the name of the {@link PersistenceService} to use
 * @return <code>true</code> if item state was updated or <code>false</code> if either the item has not been updated
 *         since <code>timestamp</code> or if the given <code>serviceId</code> does not refer to a
 *         {@link QueryablePersistenceService}
 */
public static Boolean updatedSince(Item item, AbstractInstant timestamp, String serviceId) {
    Iterable<HistoricItem> result = getAllStatesSince(item, timestamp, serviceId);
    if (result.iterator().hasNext()) {
        return true;
    } else {
        return false;
    }
}
 
Example #22
Source File: ScriptExecution.java    From smarthome with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example #23
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * 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 for which we will sum its persisted state values since <code>timestamp</code>
 * @param timestamp the point in time from which to start the summation
 * @return the sum of the state values since <code>timestamp</code>, <code>null</code> if the default persistence
 *         service is not available, or {@link DecimalType.ZERO} if no historic states could be found or if the
 *         default persistence service does not refer to a {@link QueryablePersistenceService}
 */
public static DecimalType sumSince(Item item, AbstractInstant timestamp) {
    return sumSince(item, timestamp, getDefaultServiceId());
}
 
Example #24
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * 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 timestamp the point in time from which to search for the average state value
 * @return the average state values since <code>timestamp</code>, <code>null</code> if the default persistence
 *         service is not available, or the state of the given <code>item</code> if no previous states could be
 *         found or if the default persistence service does not refer to an available
 *         {@link QueryablePersistenceService}
 */
public static DecimalType averageSince(Item item, AbstractInstant timestamp) {
    return averageSince(item, timestamp, getDefaultServiceId());
}
 
Example #25
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * 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 timestamp the point in time from which to search for the minimum state value
 * @return the historic item with the minimum state value since the given point in time, <code>null</code> if the
 *         default persistence service is not available, or a {@link HistoricItem} constructed from the
 *         <code>item</code>'s state if <code>item</code>'s state is the minimum value or if the default persistence
 *         service does not refer to an available {@link QueryablePersistenceService}
 */
public static HistoricItem minimumSince(Item item, AbstractInstant timestamp) {
    return minimumSince(item, timestamp, getDefaultServiceId());
}
 
Example #26
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Query the last update time of a given <code>item</code>. The default persistence service is used.
 *
 * @param item the item for which the last update time is to be returned
 * @return point in time of the last update to <code>item</code>, or <code>null</code> if there are no previously
 *         persisted updates or the default persistence service is not available or a
 *         {@link QueryablePersistenceService}
 */
public static AbstractInstant lastUpdate(Item item) {
    return lastUpdate(item, getDefaultServiceId());
}
 
Example #27
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * 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 timestamp the point in time to start the check
 * @return a historic item with the maximum state value since the given point in time, or <code>null</code> if the
 *         default persistence service is not available, or a {@link HistoricItem} constructed from the
 *         <code>item</code> if the default persistence service does not refer to a
 *         {@link QueryablePersistenceService}
 */
public static HistoricItem maximumSince(Item item, AbstractInstant timestamp) {
    return maximumSince(item, timestamp, getDefaultServiceId());
}
 
Example #28
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Gets the difference 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 timestamp the point in time from which to compute the delta
 * @return the difference between now and then, or <code>null</code> if there is no default persistence
 *         service available, the default persistence service is not a {@link QueryablePersistenceService}, or if
 *         there is no persisted state for the given <code>item</code> at the given <code>timestamp</code> available
 *         in the default persistence service
 */
public static DecimalType deltaSince(Item item, AbstractInstant timestamp) {
    return deltaSince(item, timestamp, getDefaultServiceId());
}
 
Example #29
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Gets the evolution rate of the state of a given <code>item</code> since a certain point in time.
 * The {@link PersistenceService} identified by the <code>serviceId</code> is used.
 *
 * @param item the item to get the evolution rate value for
 * @param timestamp the point in time from which to compute the evolution rate
 * @param serviceId the name of the {@link PersistenceService} to use
 * @return the evolution rate in percent (positive and negative) between now and then, or <code>null</code> if
 *         there is no default persistence service available, the default persistence service is not a
 *         {@link QueryablePersistenceService}, or if there is no persisted state for the given <code>item</code> at
 *         the given <code>timestamp</code>, or if there is a state but it is zero (which would cause a
 *         divide-by-zero error)
 */
public static DecimalType evolutionRate(Item item, AbstractInstant timestamp) {
    return evolutionRate(item, timestamp, getDefaultServiceId());
}
 
Example #30
Source File: PersistenceExtensions.java    From smarthome with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * 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 timestamp the point in time to start the check
 * @return <code>true</code> if item state was updated, <code>false</code> if either item has not been updated since
 *         <code>timestamp</code> or if the default persistence does not refer to a
 *         {@link QueryablePersistenceService}, or <code>null</code> if the default persistence service is not
 *         available
 */
public static Boolean updatedSince(Item item, AbstractInstant timestamp) {
    return updatedSince(item, timestamp, getDefaultServiceId());
}