001/*
002 * geordi
003 *
004 * Copyright (C) 2019 Richard "Shred" Körber
005 *   https://github.com/shred/geordi
006 *
007 * This program is free software: you can redistribute it and/or modify
008 * it under the terms of the GNU General Public License as
009 * published by the Free Software Foundation, either version 3 of the
010 * License, or (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
015 */
016package org.shredzone.geordi.service;
017
018import org.shredzone.geordi.data.Sample;
019
020/**
021 * This service remembers the last sample value stored in database. It helps that sensor
022 * values are not stored in database if the sensor is in compact mode and the value has
023 * not been changed since the last time it was stored in database.
024 */
025public interface CompactingService {
026
027    /**
028     * Checks if the given {@link Sample} can be compacted.
029     *
030     * @param sample
031     *         {@link Sample} to check
032     * @return {@code true} if the corresponding sensor is in compact mode, and the
033     * sample's value is equal to the previously stored sensor value.
034     */
035    boolean wasUnchanged(Sample sample);
036
037    /**
038     * Regenerates the last unchanged {@link Sample} before the value has changed. This
039     * way, interpolations can start from the timestamp of the last unchanged value,
040     * instead of the first unchanged value.
041     *
042     * @param sample
043     *         {@link Sample} to regenerate the last unchanged sample for
044     * @return Regenerated {@link Sample}, or {@code null} if there was no last sample
045     * that could be generated
046     */
047    Sample lastUnchanged(Sample sample);
048
049    /**
050     * Remember a {@link Sample} value.
051     *
052     * @param sample
053     *         {@link Sample} to remember
054     */
055    void rememberSample(Sample sample);
056
057}