items/item-persistence.js

  1. const log = require('../log')('items.ItemPersistence');
  2. const time = require('../time');
  3. const { getQuantity, QuantityError } = require('../quantity');
  4. const { _toOpenhabPrimitiveType, _isTimeSeries } = require('../helpers');
  5. const PersistenceExtensions = Java.type('org.openhab.core.persistence.extensions.PersistenceExtensions');
  6. const TimeSeries = Java.type('org.openhab.core.types.TimeSeries');
  7. const TypeParser = Java.type('org.openhab.core.types.TypeParser');
  8. let RiemannType = null;
  9. try {
  10. RiemannType = Java.type('org.openhab.core.persistence.extensions.PersistenceExtensions.RiemannType');
  11. } catch (e) {
  12. // Ignore TypeError due to missing class on older openHAB versions
  13. if (!(e instanceof TypeError)) throw e;
  14. }
  15. /**
  16. * @typedef {import('@js-joda/core').ZonedDateTime} time.ZonedDateTime
  17. * @private
  18. */
  19. /**
  20. * @typedef {import('@js-joda/core').Instant} time.Instant
  21. * @private
  22. */
  23. /**
  24. * @typedef {import('../quantity').Quantity} Quantity
  25. * @private
  26. */
  27. /**
  28. * @typedef {import('../items/items').TimeSeries} items.TimeSeries
  29. * @private
  30. */
  31. /**
  32. * Class representing an instance of {@link https://www.openhab.org/javadoc/latest/org/openhab/core/types/state org.openhab.core.types.State}.
  33. *
  34. * @memberof items
  35. * @hideconstructor
  36. */
  37. class PersistedState {
  38. /**
  39. * Create an PersistedState, wrapping a native openHAB HistoricState.
  40. * @param {*} rawHistoricState an instance of {@link https://www.openhab.org/javadoc/latest/org/openhab/core/types/state org.openhab.core.types.State}
  41. * @hideconstructor
  42. */
  43. constructor (rawHistoricState) {
  44. this.rawState = rawHistoricState;
  45. }
  46. /**
  47. * String representation of the Item state.
  48. * @type {string}
  49. */
  50. get state () {
  51. return this.rawState.toString();
  52. }
  53. /**
  54. * Numeric representation of Item state, or `null` if state is not numeric
  55. * @type {number|null}
  56. */
  57. get numericState () {
  58. const numericState = parseFloat(this.rawState.toString());
  59. return isNaN(numericState) ? null : numericState;
  60. }
  61. /**
  62. * Item state as {@link Quantity} or `null` if state is not Quantity-compatible or Quantity would be unit-less (without unit)
  63. * @type {Quantity|null}
  64. */
  65. get quantityState () {
  66. try {
  67. const qty = getQuantity(this.rawState.toString());
  68. return (qty !== null && qty.symbol !== null) ? qty : null;
  69. } catch (e) {
  70. if (e instanceof QuantityError) {
  71. return null;
  72. } else {
  73. throw Error('Failed to create "quantityState": ' + e);
  74. }
  75. }
  76. }
  77. toString () {
  78. return `PersistedState (State=${this.state})`;
  79. }
  80. }
  81. /**
  82. * Class representing an instance of {@link https://www.openhab.org/javadoc/latest/org/openhab/core/persistence/historicitem org.openhab.core.persistence.HistoricItem}.
  83. * Extends {@link items.PersistedState}.
  84. *
  85. * @extends PersistedState
  86. * @memberof items
  87. * @hideconstructor
  88. */
  89. class PersistedItem extends PersistedState {
  90. /**
  91. * Create a PersistedItem, wrapping a native openHAB HistoricItem.
  92. * @param {*} rawHistoricItem {@link https://www.openhab.org/javadoc/latest/org/openhab/core/persistence/historicitem org.openhab.core.persistence.HistoricItem}
  93. * @hideconstructor
  94. */
  95. constructor (rawHistoricItem) {
  96. super(rawHistoricItem.getState());
  97. this.rawHistoricItem = rawHistoricItem;
  98. }
  99. /**
  100. * Timestamp of persisted Item.
  101. *
  102. * Consider using {@link instant} for heavy calculations because it is much faster to work with Instant.
  103. * @type {time.ZonedDateTime}
  104. */
  105. get timestamp () {
  106. return time.javaZDTToJsZDT(this.rawHistoricItem.getTimestamp());
  107. }
  108. /**
  109. * Timestamp of the persisted Item as Instant.
  110. * @returns {time.Instant}
  111. */
  112. get instant () {
  113. return time.javaInstantToJsInstant(this.rawHistoricItem.getInstant());
  114. }
  115. toString () {
  116. return `PersistedItem (Timestamp=${this.timestamp}, State=${this.state})`;
  117. }
  118. }
  119. function _ZDTOrNull (result) {
  120. return result === null ? null : time.javaZDTToJsZDT(result);
  121. }
  122. function _decimalOrNull (result) {
  123. return result === null ? null : result.toBigDecimal();
  124. }
  125. function _persistedStateOrNull (result) {
  126. return result === null ? null : new PersistedState(result);
  127. }
  128. function _persistedItemOrNull (result) {
  129. if (result === null) return null;
  130. return new PersistedItem(result);
  131. }
  132. function _javaIterableOfJavaHistoricItemsToJsArrayOfHistoricItems (result) {
  133. if (result === null) return null;
  134. const historicItems = [];
  135. result.forEach((hi) => {
  136. const historicItem = _persistedItemOrNull(hi);
  137. if (historicItem !== null) historicItems.push(historicItem);
  138. });
  139. return historicItems;
  140. }
  141. /**
  142. * Class representing the historic state of an openHAB Item.
  143. * Wrapping the {@link https://www.openhab.org/javadoc/latest/org/openhab/core/persistence/extensions/persistenceextensions org.openhab.core.persistence.extensions.PersistenceExtensions}.
  144. *
  145. * Be warned: This class can throw several exceptions from the underlying Java layer. It is recommended to wrap the methods of this class inside a try_catch block!
  146. *
  147. * Please note: Several methods return <code>null</code> if the default persistence service is no queryable persistence service
  148. * or the provided <code>serviceId</code> does not refer to an available queryable persistence service.
  149. *
  150. * @memberOf items
  151. * @hideconstructor
  152. */
  153. class ItemPersistence {
  154. constructor (rawItem) {
  155. this.rawItem = rawItem;
  156. }
  157. /**
  158. * Enum of the Riemann approximation types to calculate the integral approximation.
  159. *
  160. * @type {RiemannType}
  161. */
  162. static get RiemannType () {
  163. if (RiemannType === null) {
  164. log.warn('RiemannType is not available on your openHAB version!');
  165. }
  166. return RiemannType;
  167. }
  168. /**
  169. * Persists a state of a given Item.
  170. *
  171. * There are six ways to use this method:
  172. * ```js
  173. * // Tell persistence to store the current Item state
  174. * items.MyItem.persistence.persist();
  175. * items.MyItem.persistence.persist('influxdb'); // using the InfluxDB persistence service
  176. *
  177. * // Tell persistence to store the state 'ON' at 2021-01-01 00:00:00
  178. * items.MyItem.persistence.persist(time.toZDT('2021-01-01T00:00:00'), 'ON');
  179. * items.MyItem.persistence.persist(time.toZDT('2021-01-01T00:00:00'), 'ON', 'influxdb'); // using the InfluxDB persistence service
  180. *
  181. * // Tell persistence to store a TimeSeries
  182. * items.MyItem.persistence.persist(timeSeries);
  183. * items.MyItem.persistence.persist(timeSeries, 'influxdb'); // using the InfluxDB persistence service
  184. * ```
  185. *
  186. * **Note:** The persistence service will store the state asynchronously in the background, this method will return immediately.
  187. * When storing the current state, this has the side effect, that if the Item state changes shortly the method call, the new state will be persisted.
  188. * To work around that side effect, you might add `java.lang.Thread.sleep` to your code:
  189. * ```js
  190. * items.MyItem.persistence.persist(); // Tell persistence to store the current Item state
  191. * java.lang.Thread.sleep(100); // Wait 100 ms to make sure persistence has enough time to store the current Item state
  192. * items.MyItem.postUpdate(0); // Now set the Item state to a new value
  193. * ```
  194. *
  195. * @param {(time.ZonedDateTime | Date)} [timestamp] the date for the item state to be stored
  196. * @param {string|number|time.ZonedDateTime|Quantity|HostState} [state] the state to be stored
  197. * @param {items.TimeSeries} [timeSeries] optional TimeSeries to be stored
  198. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  199. */
  200. persist (timestamp, state, timeSeries, serviceId) {
  201. switch (arguments.length) {
  202. // persist the current state
  203. case 0:
  204. this.#persistCurrentState();
  205. break;
  206. // persist the current state in a given service or persist a TimeSeries
  207. case 1:
  208. if (_isTimeSeries(arguments[0])) {
  209. this.#persistTimeSeries(arguments[0]);
  210. break;
  211. }
  212. this.#persistCurrentState(arguments[0]);
  213. break;
  214. // persist a given state at a given timestamp or persist a TimeSeries in a given service
  215. case 2:
  216. if (_isTimeSeries(arguments[0])) {
  217. this.#persistTimeSeries(arguments[0], arguments[1]);
  218. break;
  219. }
  220. this.#persistGivenState(arguments[0], arguments[1]);
  221. break;
  222. // persist a given state at a given timestamp in a given service
  223. case 3:
  224. this.#persistGivenState(arguments[0], arguments[1], arguments[2]);
  225. break;
  226. // default case
  227. default:
  228. PersistenceExtensions.persist(this.rawItem, ...arguments);
  229. break;
  230. }
  231. }
  232. /**
  233. * Internal method to persist the current state to a optionally given persistence service.
  234. * @param {string} [serviceId]
  235. */
  236. #persistCurrentState (serviceId) {
  237. log.debug(`Persisting current state of Item ${this.rawItem.getName()}${serviceId ? ' to ' + serviceId : ''} ...`);
  238. if (serviceId) {
  239. PersistenceExtensions.persist(this.rawItem, serviceId);
  240. return;
  241. }
  242. PersistenceExtensions.persist(this.rawItem);
  243. }
  244. /**
  245. * Internal method to persist a given state at a given timestamp to a optionally given persistence service.
  246. * @param {(time.ZonedDateTime | Date)} timestamp
  247. * @param {string|number|time.ZonedDateTime|Quantity|HostState} state
  248. * @param {string} [serviceId]
  249. */
  250. #persistGivenState (timestamp, state, serviceId) {
  251. if (typeof timestamp !== 'object') throw new TypeError('persist(timestamp, state, serviceId): timestamp must be a ZonedDateTime or Date object!');
  252. log.debug(`Persisting given state ${state} of Item ${this.rawItem.getName()}${serviceId ? ' to ' + serviceId : ''} ...`);
  253. if (serviceId) {
  254. PersistenceExtensions.persist(this.rawItem, timestamp, _toOpenhabPrimitiveType(state), serviceId);
  255. return;
  256. }
  257. PersistenceExtensions.persist(this.rawItem, timestamp, _toOpenhabPrimitiveType(state));
  258. }
  259. /**
  260. * Internal method to persist a given TimeSeries to a optionally given persistence service.
  261. * @param {items.TimeSeries} timeSeries
  262. * @param {string} [serviceId]
  263. */
  264. #persistTimeSeries (timeSeries, serviceId) {
  265. log.debug(`Persisting TimeSeries for Item ${this.rawItem.getName()}${serviceId ? ' to ' + serviceId : ''} ...`);
  266. // Get accepted data types of the Item to use the TypeParser
  267. const acceptedDataTypes = this.rawItem.getAcceptedDataTypes();
  268. // Create a Java TimeSeries object from the JS TimeSeries
  269. const ts = new TimeSeries(TimeSeries.Policy.valueOf(timeSeries.policy));
  270. timeSeries.states.forEach(([timestamp, state]) => {
  271. ts.add(timestamp, TypeParser.parseState(acceptedDataTypes, _toOpenhabPrimitiveType(state)));
  272. });
  273. // Persist the Java TimeSeries
  274. if (serviceId) {
  275. PersistenceExtensions.persist(this.rawItem, ts, serviceId);
  276. return;
  277. }
  278. PersistenceExtensions.persist(this.rawItem, ts);
  279. }
  280. /**
  281. * Retrieves the persisted state for a given Item at a certain point in time.
  282. *
  283. * @param {(time.ZonedDateTime | Date)} timestamp the point in time for which the persisted item should be retrieved
  284. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  285. * @returns {(PersistedItem | null)} the {@link items.PersistedItem} at the given point in time, or <code>null</code> if no persisted item could be found
  286. */
  287. persistedState (timestamp, serviceId) {
  288. return _persistedItemOrNull(PersistenceExtensions.persistedState(this.rawItem, ...arguments));
  289. }
  290. /**
  291. * Query the last update time of a given Item.
  292. *
  293. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  294. * @returns {(time.ZonedDateTime | null)} point in time of the last historic update to Item, or <code>null</code>
  295. if the current state is different from the last persisted state or there are no historic persisted updates
  296. */
  297. lastUpdate (serviceId) {
  298. return _ZDTOrNull(PersistenceExtensions.lastUpdate(this.rawItem, ...arguments));
  299. }
  300. /**
  301. * Query the next update time of a given Item.
  302. *
  303. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  304. * @returns {(time.ZonedDateTime | null)} point in time of the first future update to Item, or <code>null</code> if there are no future persisted updates
  305. */
  306. nextUpdate (serviceId) {
  307. return _ZDTOrNull(PersistenceExtensions.nextUpdate(this.rawItem, ...arguments));
  308. }
  309. /**
  310. * Query the last change time of a given Item.
  311. *
  312. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  313. * @returns {(time.ZonedDateTime | null)} point in time of the last historic change to Item, or <code>null</code>
  314. if the current state is different from the last persisted state or there are no historic persisted states
  315. */
  316. lastChange (serviceId) {
  317. return _ZDTOrNull(PersistenceExtensions.lastChange(this.rawItem, ...arguments));
  318. }
  319. /**
  320. * Query the next change time of a given Item.
  321. *
  322. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  323. * @returns {(time.ZonedDateTime | null)} point in time of the first future change to Item, or <code>null</code> if there are no future persisted states
  324. */
  325. nextChange (serviceId) {
  326. return _ZDTOrNull(PersistenceExtensions.nextChange(this.rawItem, ...arguments));
  327. }
  328. /**
  329. * Returns the previous state of a given Item.
  330. *
  331. * @param {boolean} [skipEqual] optional, if true, skips equal state values and searches the first state not equal the current state
  332. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  333. * @returns {(PersistedItem | null)} the {@link items.PersistedItem} at the given point in time, or <code>null</code> if no persisted item could be found or null
  334. */
  335. previousState (skipEqual, serviceId) {
  336. return _persistedItemOrNull(PersistenceExtensions.previousState(this.rawItem, ...arguments));
  337. }
  338. /**
  339. * Returns the next state of a given Item.
  340. *
  341. * @param {boolean} [skipEqual] optional, if true, skips equal state values and searches the first state not equal the current state
  342. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  343. * @returns {(PersistedItem | null)} the {@link items.PersistedItem} at the given point in time, or <code>null</code> if no persisted item could be found or null
  344. */
  345. nextState (skipEqual, serviceId) {
  346. return _persistedItemOrNull(PersistenceExtensions.nextState(this.rawItem, ...arguments));
  347. }
  348. /**
  349. * Checks if the state of a given Item has changed since a certain point in time.
  350. *
  351. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to start the check
  352. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  353. * @returns {boolean} <code>true</code> if item state has changed, <code>false</code> if it has not changed,
  354. * <code>null</code> if <code>timestamp</code> is in the future
  355. */
  356. changedSince (timestamp, serviceId) {
  357. return PersistenceExtensions.changedSince(this.rawItem, ...arguments);
  358. }
  359. /**
  360. * Checks if the state of a given Item will change by a certain point in time.
  361. *
  362. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to end the check
  363. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  364. * @returns {boolean} <code>true</code> if item state will change, <code>false</code> if it will not change,
  365. * <code>null</code> if <code>timestamp></code> is in the past
  366. */
  367. changedUntil (timestamp, serviceId) {
  368. return PersistenceExtensions.changedUntil(this.rawItem, ...arguments);
  369. }
  370. /**
  371. * Checks if the state of a given Item has changed between two certain points in time.
  372. *
  373. * @param {(time.ZonedDateTime | Date)} begin the point in time to start the check
  374. * @param {(time.ZonedDateTime | Date)} end the point in time to stop the check
  375. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  376. * @returns {boolean} <code>true</code> if item state changes, <code>false</code> if the item does not change in the given interval,
  377. * <code>null</code> if <code>begin</code> is after <code>end</code>
  378. */
  379. changedBetween (begin, end, serviceId) {
  380. return PersistenceExtensions.changedBetween(this.rawItem, ...arguments);
  381. }
  382. /**
  383. * Checks if the state of a given Item has been updated since a certain point in time.
  384. *
  385. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to start the check
  386. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  387. * @returns {boolean} <code>true</code> if item state was updated, <code>false</code> if the item has not been updated since <code>timestamp</code>,
  388. * <code>null</code> if <code>timestamp</code> is in the future
  389. */
  390. updatedSince (timestamp, serviceId) {
  391. return PersistenceExtensions.updatedSince(this.rawItem, ...arguments);
  392. }
  393. /**
  394. * Checks if the state of a given Item will have been updated until a certain point in time.
  395. *
  396. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to end the check
  397. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  398. * @returns {boolean} <code>true</code> if item state is updated, <code>false</code> if the item is not updated until <code>timestamp</code>,
  399. * <code>null</code> if <code>timestamp</code> is in the past
  400. */
  401. updatedUntil (timestamp, serviceId) {
  402. return PersistenceExtensions.updatedUntil(this.rawItem, ...arguments);
  403. }
  404. /**
  405. * Checks if the state of a given Item has been updated between two certain points in time.
  406. *
  407. * @param {(time.ZonedDateTime | Date)} begin the point in time to start the check
  408. * @param {(time.ZonedDateTime | Date)} end the point in time to stop the check
  409. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  410. * @returns {boolean} <code>true</code> if item state was updated, <code>false</code> if the item has not been updated in the given interval,
  411. * <code>null</code> if <code>begin</code> is after <code>end</code>
  412. */
  413. updatedBetween (begin, end, serviceId) {
  414. return PersistenceExtensions.updatedBetween(this.rawItem, ...arguments);
  415. }
  416. /**
  417. * Gets the historic Item with the maximum value of a given Item since a certain point in time.
  418. *
  419. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to start the check
  420. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  421. * @returns {(PersistedItem | null)} a {@link items.PersistedItem} with the maximum state value since the given point in time,
  422. * or <code>null</code> if <code>timestamp</code> is in the future
  423. */
  424. maximumSince (timestamp, serviceId) {
  425. return _persistedItemOrNull(PersistenceExtensions.maximumSince(this.rawItem, ...arguments));
  426. }
  427. /**
  428. * Gets the future Item with the maximum value of a given Item until a certain point in time.
  429. *
  430. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to end the check
  431. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  432. * @returns {(PersistedItem | null)} a {@link items.PersistedItem}m with the maximum state value until the given point in time,
  433. * or <code>null</code> if <code>timestamp</code> is in the past
  434. */
  435. maximumUntil (timestamp, serviceId) {
  436. return _persistedItemOrNull(PersistenceExtensions.maximumUntil(this.rawItem, ...arguments));
  437. }
  438. /**
  439. * Gets the persisted Item with the maximum value of a given Item between two certain points in time.
  440. *
  441. * @param {(time.ZonedDateTime | Date)} begin the point in time to start the check
  442. * @param {(time.ZonedDateTime | Date)} end the point in time to stop the check
  443. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  444. * @returns {(PersistedItem | null)} a {@link items.PersistedItem} with the maximum state value between two points in time,
  445. * or <code>null</code> if <code>begin</code> is after <code>end</end>
  446. */
  447. maximumBetween (begin, end, serviceId) {
  448. return _persistedItemOrNull(PersistenceExtensions.maximumBetween(this.rawItem, ...arguments));
  449. }
  450. /**
  451. * Gets the historic Item with the minimum value of a given Item since a certain point in time.
  452. *
  453. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to start the check
  454. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  455. * @returns {(PersistedItem | null)} a {@link items.PersistedItem} with the minimum state value since the given point in time,
  456. * or <code>null</code> if <code>timestamp</code> is in the future
  457. */
  458. minimumSince (timestamp, serviceId) {
  459. return _persistedItemOrNull(PersistenceExtensions.minimumSince(this.rawItem, ...arguments));
  460. }
  461. /**
  462. * Gets the future Item with the minimum value of a given Item until a certain point in time.
  463. *
  464. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to end the check
  465. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  466. * @returns {(PersistedItem | null)} a {@link items.PersistedItem} with the minimum state value until the given point in time,
  467. * or <code>null</code> if <code>timestamp</code> is in the past
  468. */
  469. minimumUntil (timestamp, serviceId) {
  470. return _persistedItemOrNull(PersistenceExtensions.minimumUntil(this.rawItem, ...arguments));
  471. }
  472. /**
  473. * Gets the state with the minimum value of a given Item between two certain points in time.
  474. *
  475. * @param {(time.ZonedDateTime | Date)} begin the point in time to start the check
  476. * @param {(time.ZonedDateTime | Date)} end the point in time to stop the check
  477. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  478. * @returns {(PersistedItem | null)} a {@link items.PersistedItem} with the minimum state value between two points in time,
  479. * or <code>null</code> if <code>begin</code> is after <code>end</end>
  480. */
  481. minimumBetween (begin, end, serviceId) {
  482. return _persistedItemOrNull(PersistenceExtensions.minimumBetween(this.rawItem, ...arguments));
  483. }
  484. /**
  485. * Gets the variance of the state of the given Item since a certain point in time.
  486. *
  487. * @param {(time.ZonedDateTime | Date)} timestamp the point in time from which to compute the variance
  488. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  489. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  490. * default <code>LEFT</code>
  491. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  492. * @returns {(PersistedState | null)} the variance between then and now as {@link items.PersistedState}, or <code>null</code> if
  493. * <code>timestamp</code> is in the future, or if there is no persisted state for the given
  494. * Item at the given <code>timestamp</code>
  495. */
  496. varianceSince (timestamp, riemannType, serviceId) {
  497. return _persistedStateOrNull(PersistenceExtensions.varianceSince(this.rawItem, ...arguments));
  498. }
  499. /**
  500. * Gets the variance of the state of the given Item until a certain point in time.
  501. *
  502. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to which to compute the variance
  503. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  504. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  505. * default <code>LEFT</code>
  506. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  507. * @returns {(PersistedState | null)} the variance between now and then as {@link items.PersistedState}, or <code>null</code> if
  508. * <code>timestamp</code> is in the past, or if there is no persisted state for the given
  509. * Item at the given <code>timestamp</code>
  510. */
  511. varianceUntil (timestamp, riemannType, serviceId) {
  512. return _persistedStateOrNull(PersistenceExtensions.varianceUntil(this.rawItem, ...arguments));
  513. }
  514. /**
  515. * Gets the variance of the state of the given Item between two certain points in time.
  516. *
  517. * @param {(time.ZonedDateTime | Date)} begin the point in time from which to compute the variance
  518. * @param {(time.ZonedDateTime | Date)} end the end time for the computation
  519. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  520. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  521. * default <code>LEFT</code>
  522. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  523. * @returns {(PersistedState | null)} the variance between both points of time as {@link items.PersistedState}, or <code>null</code> if
  524. * <code>begin</code> is after <code>end</code>, or if there is no persisted state for the given
  525. * Item between <code>begin</code> and <code>end</code>
  526. */
  527. varianceBetween (begin, end, riemannType, serviceId) {
  528. return _persistedStateOrNull(PersistenceExtensions.varianceBetween(this.rawItem, ...arguments));
  529. }
  530. /**
  531. * Gets the standard deviation of the state of the given Item since a certain point in time.
  532. *
  533. * @param {(time.ZonedDateTime | Date)} timestamp the point in time from which to compute the standard deviation
  534. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  535. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  536. * default <code>LEFT</code>
  537. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  538. * @returns {(PersistedState | null)} the standard deviation between then and now as {@link items.PersistedState}, or <code>null</code>
  539. * if <code>timestamp</code> is in the future, or if there is no persisted state for the given Item
  540. * at the given <code>timestamp</code>
  541. */
  542. deviationSince (timestamp, riemannType, serviceId) {
  543. return _persistedStateOrNull(PersistenceExtensions.deviationSince(this.rawItem, ...arguments));
  544. }
  545. /**
  546. * Gets the standard deviation of the state of the given Item until a certain point in time.
  547. *
  548. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to which to compute the standard deviation
  549. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  550. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  551. * default <code>LEFT</code>
  552. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  553. * @returns {(PersistedState | null)} the standard deviation between now and then as {@link items.PersistedState}, or <code>null</code>
  554. * if <code>timestamp</code> is in the past, or if there is no persisted state for the given Item
  555. * at the given <code>timestamp</code>
  556. */
  557. deviationUntil (timestamp, riemannType, serviceId) {
  558. return _persistedStateOrNull(PersistenceExtensions.deviationUntil(this.rawItem, ...arguments));
  559. }
  560. /**
  561. * Gets the standard deviation of the state of the given Item between two certain points in time.
  562. *
  563. * @param {(time.ZonedDateTime | Date)} begin the point in time from which to compute
  564. * @param {(time.ZonedDateTime | Date)} end the end time for the computation
  565. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  566. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  567. * default <code>LEFT</code>
  568. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  569. * @returns {(PersistedState | null)} the standard deviation between both points of time as {@link items.PersistedState}, or <code>null</code>
  570. * if <code>begin</code> is after <code>end</code>, or if there is no persisted state for the given Item
  571. * between <code>begin</code> and <code>end</code>
  572. */
  573. deviationBetween (begin, end, riemannType, serviceId) {
  574. return _persistedStateOrNull(PersistenceExtensions.deviationBetween(this.rawItem, ...arguments));
  575. }
  576. /**
  577. * Gets the average value of the state of a given Item since a certain point in time.
  578. *
  579. * @example
  580. * var yesterday = time.toZDT().minusDays(1);
  581. * var item = items.getItem('KitchenDimmer');
  582. * console.log('KitchenDimmer average since yesterday', item.persistence.averageSince(yesterday));
  583. *
  584. * @param {(time.ZonedDateTime | Date)} timestamp the point in time from which to search for the average value
  585. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  586. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  587. * default <code>LEFT</code>
  588. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  589. * @returns {(PersistedState | null)} the average value since <code>timestamp</code> as {@link items.PersistedState} or <code>null</code> if no previous states could be found
  590. */
  591. averageSince (timestamp, riemannType, serviceId) {
  592. return _persistedStateOrNull(PersistenceExtensions.averageSince(this.rawItem, ...arguments));
  593. }
  594. /**
  595. * Gets the average value of the state of a given Item until a certain point in time.
  596. *
  597. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to which to search for the average value
  598. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  599. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  600. * default <code>LEFT</code>
  601. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  602. * @returns {(PersistedState | null)} the average value until <code>timestamp</code> as {@link items.PersistedState} or <code>null</code> if no future states could be found
  603. */
  604. averageUntil (timestamp, riemannType, serviceId) {
  605. return _persistedStateOrNull(PersistenceExtensions.averageUntil(this.rawItem, ...arguments));
  606. }
  607. /**
  608. * Gets the average value of the state of a given Item between two certain points in time.
  609. *
  610. * @param {(time.ZonedDateTime | Date)} begin the point in time from which to start the average
  611. * @param {(time.ZonedDateTime | Date)} end the point in time to which to start the average
  612. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  613. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  614. * default <code>LEFT</code>
  615. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  616. * @returns {(PersistedState | null)} the average value between <code>begin</code> and <code>end</code> as {@link items.PersistedState} or <code>null</code> if no states could be found
  617. */
  618. averageBetween (begin, end, riemannType, serviceId) {
  619. return _persistedStateOrNull(PersistenceExtensions.averageBetween(this.rawItem, ...arguments));
  620. }
  621. /**
  622. * Gets the Riemann sum of the states of a given Item since a certain point in time, time is calculated in seconds.
  623. *
  624. * @example
  625. * var yesterday = time.toZDT().minusDays(1);
  626. * var item = items.getItem('SolarPower');
  627. * console.log('Solar energy production since yesterday', item.persistence.riemannSumSince(yesterday));
  628. *
  629. * @param {(time.ZonedDateTime | Date)} timestamp the point in time from which to search for the Riemann sum
  630. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  631. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  632. * default <code>LEFT</code>
  633. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  634. * @returns {(PersistedState | null)} the Riemann sum since <code>timestamp</code> as {@link items.PersistedState} or <code>null</code> if no previous states could be found, time is calculated in seconds
  635. */
  636. riemannSumSince (timestamp, riemannType, serviceId) {
  637. return _persistedStateOrNull(PersistenceExtensions.riemannSumSince(this.rawItem, ...arguments));
  638. }
  639. /**
  640. * Gets the Riemann sum of the states of a given Item until a certain point in time, time is calculated in seconds.
  641. *
  642. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to which to search for the Riemann sum
  643. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  644. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  645. * default <code>LEFT</code>
  646. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  647. * @returns {(PersistedState | null)} the Riemann sum until <code>timestamp</code> as {@link items.PersistedState} or <code>null</code> if no future states could be found, time is calculated in seconds
  648. */
  649. riemannSumUntil (timestamp, riemannType, serviceId) {
  650. return _persistedStateOrNull(PersistenceExtensions.riemannSumUntil(this.rawItem, ...arguments));
  651. }
  652. /**
  653. * Gets the Riemann sum of the states of a given Item between two certain points in time, time is calculated in seconds.
  654. *
  655. * @param {(time.ZonedDateTime | Date)} begin the point in time from which to start the Riemann sum
  656. * @param {(time.ZonedDateTime | Date)} end the point in time to which to start the Riemann sum
  657. * @param {RiemannType} [riemannType] optional Riemann approximation type to calculate the integral approximation
  658. * (<code>LEFT</code>, <code>RIGHT</code>, <code>TRAPEZOIDAL</code>, <code>MIDPOINT</code>),
  659. * default <code>LEFT</code>
  660. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  661. * @returns {(PersistedState | null)} the Riemann sum between <code>begin</code> and <code>end</code> as {@link items.PersistedState} or <code>null</code> if no states could be found, time is calculated in seconds
  662. */
  663. riemannSumBetween (begin, end, riemannType, serviceId) {
  664. return _persistedStateOrNull(PersistenceExtensions.riemannSumBetween(this.rawItem, ...arguments));
  665. }
  666. /**
  667. * Gets the median value of the state of a given Item since a certain point in time.
  668. *
  669. * @example
  670. * var yesterday = time.toZDT().minusDays(1);
  671. * var item = items.getItem('KitchenDimmer');
  672. * console.log('KitchenDimmer median since yesterday', item.persistence.medianSince(yesterday));
  673. *
  674. * @param {(time.ZonedDateTime | Date)} timestamp the point in time from which to search for the median value
  675. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  676. * @returns {(PersistedState | null)} the median value since <code>timestamp</code> as {@link items.PersistedState} or <code>null</code> if no previous states could be found
  677. */
  678. medianSince (timestamp, serviceId) {
  679. return _persistedStateOrNull(PersistenceExtensions.medianSince(this.rawItem, ...arguments));
  680. }
  681. /**
  682. * Gets the median value of the state of a given Item until a certain point in time.
  683. *
  684. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to which to search for the median value
  685. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  686. * @returns {(PersistedState | null)} the median value until <code>timestamp</code> as {@link items.PersistedState} or <code>null</code> if no future states could be found
  687. */
  688. medianUntil (timestamp, serviceId) {
  689. return _persistedStateOrNull(PersistenceExtensions.medianUntil(this.rawItem, ...arguments));
  690. }
  691. /**
  692. * Gets the median value of the state of a given Item between two certain points in time.
  693. *
  694. * @param {(time.ZonedDateTime | Date)} begin the point in time from which to start the median
  695. * @param {(time.ZonedDateTime | Date)} end the point in time to which to start the median
  696. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  697. * @returns {(PersistedState | null)} the median value between <code>begin</code> and <code>end</code> as {@link items.PersistedState} or <code>null</code> if no states could be found
  698. */
  699. medianBetween (begin, end, serviceId) {
  700. return _persistedStateOrNull(PersistenceExtensions.medianBetween(this.rawItem, ...arguments));
  701. }
  702. /**
  703. * Gets the sum of the states of a given Item since a certain point in time.
  704. *
  705. * @param {(time.ZonedDateTime | Date)} timestamp the point in time from which to start the summation
  706. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  707. * @returns {(PersistedState | null)} the sum of the state values since <code>timestamp</code> as {@link items.PersistedState}, or null if <code>timestamp</code> is in the future
  708. */
  709. sumSince (timestamp, serviceId) {
  710. return _persistedStateOrNull(PersistenceExtensions.sumSince(this.rawItem, ...arguments));
  711. }
  712. /**
  713. * Gets the sum of the states of a given Item until a certain point in time.
  714. *
  715. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to which to start the summation
  716. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  717. * @returns {(PersistedState | null)} the sum of the state values until <code>timestamp</code> as {@link items.PersistedState}, or null if <code>timestamp</code> is in the past
  718. */
  719. sumUntil (timestamp, serviceId) {
  720. return _persistedStateOrNull(PersistenceExtensions.sumUntil(this.rawItem, ...arguments));
  721. }
  722. /**
  723. * Gets the sum of the states of a given Item between two certain points in time.
  724. *
  725. * @param {(time.ZonedDateTime | Date)} begin the point in time from which to start the summation
  726. * @param {(time.ZonedDateTime | Date)} end the point in time to which to start the summation
  727. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  728. * @returns {(PersistedState | null)} the sum of the state values between the given points in time as {@link items.PersistedState},
  729. * or null if <code>begin</code> is after <code>end</code>
  730. */
  731. sumBetween (begin, end, serviceId) {
  732. return _persistedStateOrNull(PersistenceExtensions.sumBetween(this.rawItem, ...arguments));
  733. }
  734. /**
  735. * Gets the difference value of the state of a given Item since a certain point in time.
  736. *
  737. * @param {(time.ZonedDateTime | Date)} timestamp the point in time from which to compute the delta
  738. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  739. * @returns {(PersistedState | null)} the difference between now and then as {@link items.PersistedState}, or <code>null</code>
  740. * if there is no persisted state for the given Item at the given <code>timestamp</code> available
  741. */
  742. deltaSince (timestamp, serviceId) {
  743. return _persistedStateOrNull(PersistenceExtensions.deltaSince(this.rawItem, ...arguments));
  744. }
  745. /**
  746. * Gets the difference value of the state of a given Item until a certain point in time.
  747. *
  748. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to which to compute the delta
  749. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  750. * @returns {(PersistedState | null)} the difference between then and now as {@link items.PersistedState}, or <code>null</code>
  751. * if there is no persisted state for the given Item at the given <code>timestamp</code> available
  752. */
  753. deltaUntil (timestamp, serviceId) {
  754. return _persistedStateOrNull(PersistenceExtensions.deltaUntil(this.rawItem, ...arguments));
  755. }
  756. /**
  757. * Gets the difference value of the state of a given Item between two certain points in time.
  758. *
  759. * @param {(time.ZonedDateTime | Date)} begin the beginning point in time
  760. * @param {(time.ZonedDateTime | Date)} end the end point in time
  761. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  762. * @returns {(PersistedState | null)} the difference between end and begin as {@link items.PersistedState}, or <code>null</code>
  763. * if there is no persisted state for the given Item for the given points in time
  764. */
  765. deltaBetween (begin, end, serviceId) {
  766. return _persistedStateOrNull(PersistenceExtensions.deltaBetween(this.rawItem, ...arguments));
  767. }
  768. /**
  769. * Gets the evolution rate of the state of a given Item since a certain point in time.
  770. *
  771. * @param {(time.ZonedDateTime | Date)} timestamp the point in time from which to compute the evolution rate
  772. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  773. * @returns {(number | null)} the evolution rate in percent (positive and negative) between then and now, or <code>null</code>
  774. * if there is no persisted state for the given Item at the given <code>timestamp</code>,
  775. * or if there is a state, but it is zero (which would cause a divide-by-zero error)
  776. */
  777. evolutionRateSince (timestamp, serviceId) {
  778. return _decimalOrNull(PersistenceExtensions.evolutionRateSince(this.rawItem, ...arguments));
  779. }
  780. /**
  781. * Gets the evolution rate of the state of a given Item until a certain point in time.
  782. *
  783. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to which to compute the evolution rate
  784. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  785. * @returns {(number | null)} the evolution rate in percent (positive and negative) between then and now, or <code>null</code>
  786. * if there is no persisted state for the given Item at the given <code>timestamp</code>,
  787. * or if there is a state, but it is zero (which would cause a divide-by-zero error)
  788. */
  789. evolutionRateUntil (timestamp, serviceId) {
  790. return _decimalOrNull(PersistenceExtensions.evolutionRateUntil(this.rawItem, ...arguments));
  791. }
  792. /**
  793. * Gets the evolution rate of the state of a given Item between two certain points in time.
  794. *
  795. * @param {(time.ZonedDateTime | Date)} begin the beginning point in time
  796. * @param {(time.ZonedDateTime | Date)} end the end point in time
  797. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  798. * @returns {(number | null)} the evolution rate in percent (positive and negative) in the given interval, or <code>null</code>
  799. * if there are no persisted states for the given Item at the given interval, or if there is a state,
  800. * but it is zero (which would cause a divide-by-zero error)
  801. */
  802. evolutionRateBetween (begin, end, serviceId) {
  803. return _decimalOrNull(PersistenceExtensions.evolutionRateBetween(this.rawItem, ...arguments));
  804. }
  805. /**
  806. * Gets the number of available historic data points of a given Item since a certain point in time.
  807. *
  808. * @param {(time.ZonedDateTime | Date)} timestamp the beginning point in time
  809. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  810. * @returns {number} the number of values persisted for this item, <code>null</code> if <code>timestamp</code> is in the future
  811. */
  812. countSince (timestamp, serviceId) {
  813. return PersistenceExtensions.countSince(this.rawItem, ...arguments);
  814. }
  815. /**
  816. * Gets the number of available future data points of a given Item until a certain point in time.
  817. *
  818. * @param {(time.ZonedDateTime | Date)} timestamp the ending point in time
  819. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  820. * @returns {number} the number of values persisted for this item, <code>null</code> if <code>timestamp</code> is in the past
  821. */
  822. countUntil (timestamp, serviceId) {
  823. return PersistenceExtensions.countUntil(this.rawItem, ...arguments);
  824. }
  825. /**
  826. * Gets the number of available persisted data points of a given Item between two certain points in time.
  827. *
  828. * @param {(time.ZonedDateTime | Date)} begin the beginning point in time
  829. * @param {(time.ZonedDateTime | Date)} end the end point in time
  830. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  831. * @returns {number} the number of values persisted for this item, <code>null</code> if <code>begin</code> is after <code>end</code>
  832. */
  833. countBetween (begin, end, serviceId) {
  834. return PersistenceExtensions.countBetween(this.rawItem, ...arguments);
  835. }
  836. /**
  837. * Gets the number of changes in historic data points of a given Item since a certain point in time.
  838. *
  839. * @param {(time.ZonedDateTime | Date)} timestamp the beginning point in time
  840. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  841. * @returns {number} the number of state changes for this item
  842. */
  843. countStateChangesSince (timestamp, serviceId) {
  844. return PersistenceExtensions.countStateChangesSince(this.rawItem, ...arguments);
  845. }
  846. /**
  847. * Gets the number of changes in future data points of a given Item until a certain point in time.
  848. *
  849. * @param {(time.ZonedDateTime | Date)} timestamp the ending point in time
  850. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  851. * @returns {number} the number of state changes for this item
  852. */
  853. countStateChangesUntil (timestamp, serviceId) {
  854. return PersistenceExtensions.countStateChangesUntil(this.rawItem, ...arguments);
  855. }
  856. /**
  857. * Gets the number of changes in persisted data points of a given Item between two certain points in time.
  858. *
  859. * @param {(time.ZonedDateTime | Date)} begin the beginning point in time
  860. * @param {(time.ZonedDateTime | Date)} end the end point in time
  861. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  862. * @returns {number} the number of state changes for this item
  863. */
  864. countStateChangesBetween (begin, end, serviceId) {
  865. return PersistenceExtensions.countStateChangesBetween(this.rawItem, ...arguments);
  866. }
  867. /**
  868. * Retrieves the historic Items for a given Item since a certain point in time.
  869. *
  870. * @param {(time.ZonedDateTime | Date)} timestamp the point in time from which to retrieve the states
  871. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  872. * @returns {PersistedItem[]} the {@link items.PersistedItem}s since the given point in time
  873. */
  874. getAllStatesSince (timestamp, serviceId) {
  875. return _javaIterableOfJavaHistoricItemsToJsArrayOfHistoricItems(PersistenceExtensions.getAllStatesSince(this.rawItem, ...arguments));
  876. }
  877. /**
  878. * Retrieves the future Items for a given Item until a certain point in time.
  879. *
  880. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to which to retrieve the states
  881. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  882. * @returns {PersistedItem[]} the future {@link items.PersistedItem}s to the given point in time
  883. */
  884. getAllStatesUntil (timestamp, serviceId) {
  885. return _javaIterableOfJavaHistoricItemsToJsArrayOfHistoricItems(PersistenceExtensions.getAllStatesUntil(this.rawItem, ...arguments));
  886. }
  887. /**
  888. * Retrieves the persisted Items for a given Item between two certain points in time.
  889. *
  890. * @param {(time.ZonedDateTime | Date)} begin the point in time from which to retrieve the states
  891. * @param {(time.ZonedDateTime | Date)} end the point in time to which to retrieve the states
  892. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  893. * @returns {PersistedItem[]} the historic {@link items.PersistedItem}s between the given points in time,
  894. */
  895. getAllStatesBetween (begin, end, serviceId) {
  896. return _javaIterableOfJavaHistoricItemsToJsArrayOfHistoricItems(PersistenceExtensions.getAllStatesBetween(this.rawItem, ...arguments));
  897. }
  898. /**
  899. * Removes from persistence the historic items for a given Item since a certain point in time.
  900. * This will only have effect if the persistence service is a modifiable persistence service.
  901. *
  902. * @param {(time.ZonedDateTime | Date)} timestamp the point in time from which to remove the states
  903. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  904. */
  905. removeAllStatesSince (timestamp, serviceId) {
  906. return PersistenceExtensions.removeAllStatesSince(this.rawItem, ...arguments);
  907. }
  908. /**
  909. * Removes from persistence the future items for a given Item until a certain point in time.
  910. * This will only have effect if the persistence service is a modifiable persistence service.
  911. *
  912. * @param {(time.ZonedDateTime | Date)} timestamp the point in time to which to remove the states
  913. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  914. */
  915. removeAllStatesUntil (timestamp, serviceId) {
  916. return PersistenceExtensions.removeAllStatesUntil(this.rawItem, ...arguments);
  917. }
  918. /**
  919. * Removes from persistence the persisted items for a given Item between two certain points in time.
  920. * This will only have effect if the persistence service is a modifiable persistence service.
  921. *
  922. * @param {(time.ZonedDateTime | Date)} begin the point in time from which to remove the states
  923. * @param {(time.ZonedDateTime | Date)} end the point in time to which to remove the states
  924. * @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
  925. */
  926. removeAllStatesBetween (begin, end, serviceId) {
  927. return PersistenceExtensions.removeAllStatesBetween(this.rawItem, ...arguments);
  928. }
  929. }
  930. module.exports = ItemPersistence;