Package be.gaudry.model.brolmeter
Class Meter
java.lang.Object
be.gaudry.model.AbstractLightObject
be.gaudry.model.brolmeter.Meter
- All Implemented Interfaces:
ILightObject
,Serializable
- Direct Known Subclasses:
MeterHibernateWrapper
,VehicleMeter
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 Summary
Modifier and TypeFieldDescriptionprotected boolean
When dirty istrue
, the relative measures must be re-evaluated the next time they are asked for.Fields inherited from interface be.gaudry.model.ILightObject
DEFAULT_ID
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
adaptMeasures(Collection<Measure> indexes, List<Measure> relatives)
Indexes are simply the meter indexes (the total amount of consumption).void
addMeasure(Measure measure)
Deprecated.void
addMeasure(Date date, double value)
Builds and adds aMeasure
for this meter.void
addMeasure(Date date, double value, String comment)
Builds and adds aMeasure
for this meter.void
Gets a readable display of a Meter.int
getId()
Identifier of the ILightObjectReturns an unmodifiable view of the measures (only indexes of the meter).Returns an unmodifiable view of the relative measures (differences between two indexes).getUnit()
boolean
isDirty()
Adding or removing measures from the indexes may lead to dirty relative measures (i.e.void
setDisplay(String display)
Sets the display.void
setId(int id)
void
toString()
Builds a string with variables values and the class.Methods inherited from class be.gaudry.model.AbstractLightObject
equals, hashCode
-
Field Details
-
dirty
protected boolean dirtyWhen dirty istrue
, the relative measures must be re-evaluated the next time they are asked for.
-
-
Constructor Details
-
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
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
Sets the display. \nnull value allowed to reset the display and forces using theEMeterType.toString()
method.- Parameters:
display
- String representation of the object- See Also:
ILightObject.getDisplay()
-
getMeterType
- Returns:
- the meterType
-
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 theCollections.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 implementRandomAccess
if the specified list does.- Returns:
- an unmodifiable view of the measures (never null).
-
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 aredirty
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 implementRandomAccess
if the specified list does.- Returns:
- an unmodifiable view of the measures (never null).
- See Also:
adaptMeasures(Collection, List)
-
setUnit
- Parameters:
unit
- the unit to set
-
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
Deprecated.useaddMeasure(Date, double)
instead of this (will be protected into next versions)Adds aMeasure
for this meter. \nSets also themeasure meter
with this.- Parameters:
measure
-
-
addMeasure
Builds and adds aMeasure
for this meter.- Parameters:
date
-value
-
-
addMeasure
Builds and adds aMeasure
for this meter.- Parameters:
date
-value
-comment
-
-
clearMeasures
public void clearMeasures() -
adaptMeasures
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 measuresrelatives
- differences measures between indexes
-
toString
Description copied from class:AbstractLightObject
Builds a string with variables values and the class.- Overrides:
toString
in classAbstractLightObject
- Returns:
- a String representation of this LightObject only for debugging
- See Also:
Object.toString()
-
addMeasure(Date, double)
instead of this (will be protected into next versions)