PersistenceExtensions { public static HistoricItem previousState(Item item) { return previousState(item, false); } @Activate  PersistenceExtensions(@Reference PersistenceServiceRegistry registry); static void persist(Item item, String serviceId); static void persist(Item item); static HistoricItem historicState(Item item, ZonedDateTime timestamp); static HistoricItem historicState(Item item, ZonedDateTime timestamp, String serviceId); static Boolean changedSince(Item item, ZonedDateTime timestamp); static Boolean changedSince(Item item, ZonedDateTime timestamp, String serviceId); static Boolean updatedSince(Item item, ZonedDateTime timestamp); static Boolean updatedSince(Item item, ZonedDateTime timestamp, String serviceId); static HistoricItem maximumSince(Item item, ZonedDateTime timestamp); static HistoricItem maximumSince(final Item item, ZonedDateTime timestamp, String serviceId); static HistoricItem minimumSince(Item item, ZonedDateTime timestamp); static HistoricItem minimumSince(final Item item, ZonedDateTime timestamp, String serviceId); static DecimalType varianceSince(Item item, ZonedDateTime timestamp); static DecimalType varianceSince(Item item, ZonedDateTime timestamp, String serviceId); static DecimalType deviationSince(Item item, ZonedDateTime timestamp); static DecimalType deviationSince(Item item, ZonedDateTime timestamp, String serviceId); static DecimalType averageSince(Item item, ZonedDateTime timestamp); static DecimalType averageSince(Item item, ZonedDateTime timestamp, String serviceId); static DecimalType sumSince(Item item, ZonedDateTime timestamp); static DecimalType sumSince(Item item, ZonedDateTime timestamp, String serviceId); static ZonedDateTime lastUpdate(Item item); static ZonedDateTime lastUpdate(Item item, String serviceId); static DecimalType deltaSince(Item item, ZonedDateTime timestamp); static DecimalType deltaSince(Item item, ZonedDateTime timestamp, String serviceId); static DecimalType evolutionRate(Item item, ZonedDateTime timestamp); static DecimalType evolutionRate(Item item, ZonedDateTime timestamp, String serviceId); static HistoricItem previousState(Item item); static HistoricItem previousState(Item item, boolean skipEqual); static HistoricItem previousState(Item item, boolean skipEqual, String serviceId);  }
@Test public void testPreviousStateNoSkip() { item.setState(new DecimalType(4321)); HistoricItem prevStateItem = PersistenceExtensions.previousState(item, false, TestPersistenceService.ID); assertNotNull(prevStateItem); assertEquals("2012", prevStateItem.getState().toString()); item.setState(new DecimalType(2012)); prevStateItem = PersistenceExtensions.previousState(item, false, TestPersistenceService.ID); assertNotNull(prevStateItem); assertEquals("2012", prevStateItem.getState().toString()); prevStateItem = PersistenceExtensions.previousState(item, false); assertNull(prevStateItem); }
@Test public void testPreviousStateSkip() { item.setState(new DecimalType(2012)); HistoricItem prevStateItem = PersistenceExtensions.previousState(item, true, TestPersistenceService.ID); assertNotNull(prevStateItem); assertEquals("2011", prevStateItem.getState().toString()); prevStateItem = PersistenceExtensions.previousState(item, true); assertNull(prevStateItem); }