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
FieldsModifier and TypeFieldDescriptionprotected booleanWhen 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidadaptMeasures(Collection<Measure> indexes, List<Measure> relatives)Indexes are simply the meter indexes (the total amount of consumption).voidaddMeasure(Measure measure)Deprecated.voidaddMeasure(Date date, double value)Builds and adds aMeasurefor this meter.voidaddMeasure(Date date, double value, String comment)Builds and adds aMeasurefor this meter.voidGets a readable display of a Meter.intgetId()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()booleanisDirty()Adding or removing measures from the indexes may lead to dirty relative measures (i.e.voidsetDisplay(String display)Sets the display.voidsetId(int id)voidtoString()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:ILightObjectIdentifier 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 implementRandomAccessif 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 aredirtyand 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 implementRandomAccessif 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:
trueif the measures are dirty
-
addMeasure
Deprecated.useaddMeasure(Date, double)instead of this (will be protected into next versions)Adds aMeasurefor this meter. \nSets also themeasure meterwith this.- Parameters:
measure-
-
addMeasure
Builds and adds aMeasurefor this meter.- Parameters:
date-value-
-
addMeasure
Builds and adds aMeasurefor 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:AbstractLightObjectBuilds a string with variables values and the class.- Overrides:
toStringin 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)