Class Meter

java.lang.Object
be.gaudry.model.AbstractLightObject
be.gaudry.model.brolmeter.Meter
All Implemented Interfaces:
ILightObject, Serializable
Direct Known Subclasses:
MeterHibernateWrapper, VehicleMeter

public class Meter extends AbstractLightObject
Adding or removing measures from the indexes may lead to dirty relative measures (i.e. adding an index with an oldest date than the last index). This method sort the original measures (indexes), and re-evaluate the relative measures. The cost of maintaining relative measures is minimized by the fact nothing is done on an insert or a remove, but the state is set to dirty, and the relative measures must be re-evaluated the next time they will be asked for. Asking for relative measures if dirty flag is not set has no cost.
Since:
1.0 Feb 7, 2009
Author:
Steph GAUDRY
See Also:
Serialized Form
  • Field Details

    • dirty

      protected boolean dirty
      When dirty is true, the relative measures must be re-evaluated the next time they are asked for.
  • Constructor Details

    • Meter

      public Meter()
    • Meter

      public Meter(String display, String unit)
      Parameters:
      display - name of the meter
      unit - measure unit of the meter
    • Meter

      public Meter(int id, EMeterType meterType, String unit)
      Parameters:
      id -
      meterType -
      unit -
    • Meter

      public Meter(Meter model)
      Builds a new Meter, like a copy of the given meter, but without any measure
      Parameters:
      model - Meter to copy
  • Method Details

    • getId

      public int getId()
      Description copied from interface: ILightObject
      Identifier of the ILightObject
      Returns:
      the id
    • setId

      public void setId(int id)
      Parameters:
      id - the id to set
      See Also:
      ILightObject.getId()
    • getDisplay

      public String getDisplay()
      Gets a readable display of a Meter. If no custom display is set, returns the localized type of the Meter.
      Returns:
      the display
      See Also:
      EMeterType.toString()
    • setDisplay

      public void setDisplay(String display)
      Sets the display. \nnull value allowed to reset the display and forces using the EMeterType.toString() method.
      Parameters:
      display - String representation of the object
      See Also:
      ILightObject.getDisplay()
    • getMeterType

      public EMeterType getMeterType()
      Returns:
      the meterType
    • getMeasures

      public Collection<Measure> getMeasures()
      Returns an unmodifiable view of the measures (only indexes of the meter). This collection is sorted by insertion order and not by date; call the Collections.sort(List) method to sort by date. \n This method allows modules to provide users with "read-only" access to the measures. Query operations on the returned list "read through" to the specified list, and attempts to modify the returned list, whether direct or via its iterator, result in an UnsupportedOperationException. \n \n The returned list will be serializable if the specified list is serializable. Similarly, the returned list will implement RandomAccess if the specified list does.
      Returns:
      an unmodifiable view of the measures (never null).
    • getRelativeMeasures

      public final Collection<Measure> getRelativeMeasures()
      Returns an unmodifiable view of the relative measures (differences between two indexes). This collection is sorted by date. \n This method may have a cost if we have added some measures since the last call (when we add a measure, the relative measures are dirty and must be re-evaluated when we ask for it). \n This method allows modules to provide users with "read-only" access to the measures. Query operations on the returned list "read through" to the specified list, and attempts to modify the returned list, whether direct or via its iterator, result in an UnsupportedOperationException. \n \n The returned list will be serializable if the specified list is serializable. Similarly, the returned list will implement RandomAccess if the specified list does.
      Returns:
      an unmodifiable view of the measures (never null).
      See Also:
      adaptMeasures(Collection, List)
    • setUnit

      public void setUnit(String unit)
      Parameters:
      unit - the unit to set
    • getUnit

      public String getUnit()
      Returns:
      the unit
    • isDirty

      public boolean isDirty()
      Adding or removing measures from the indexes may lead to dirty relative measures (i.e. adding an index with an oldest date than the last index). This method sort the original measures (indexes), and re-evaluate the relative measures. The cost of maintaining relative measures is minimized by the fact nothing is done on an insert or a remove, but the state is set to dirty, and the relative measures must be re-evaluated the next time they will be asked for. Asking for relative measures if dirty flag is not set has no cost.
      Returns:
      true if the measures are dirty
    • addMeasure

      public void addMeasure(Measure measure)
      Deprecated.
      use addMeasure(Date, double) instead of this (will be protected into next versions)
      Adds a Measure for this meter. \nSets also the measure meter with this.
      Parameters:
      measure -
    • addMeasure

      public void addMeasure(Date date, double value)
      Builds and adds a Measure for this meter.
      Parameters:
      date -
      value -
    • addMeasure

      public void addMeasure(Date date, double value, String comment)
      Builds and adds a Measure for this meter.
      Parameters:
      date -
      value -
      comment -
    • clearMeasures

      public void clearMeasures()
    • adaptMeasures

      public static void adaptMeasures(Collection<Measure> indexes, List<Measure> relatives)
      Indexes are simply the meter indexes (the total amount of consumption). \nRelatives measures are evaluated as the difference with previous index of a meter. \nindexes may be modified (they are sorted) \nrelatives are modified (clean, and re-feeded)
      Parameters:
      indexes - total amount of consumption measures
      relatives - differences measures between indexes
    • toString

      public String toString()
      Description copied from class: AbstractLightObject
      Builds a string with variables values and the class.
      Overrides:
      toString in class AbstractLightObject
      Returns:
      a String representation of this LightObject only for debugging
      See Also:
      Object.toString()