Package com.storedobject.iot
Class Consumption<P extends PeriodType>
java.lang.Object
com.storedobject.core.StoredObject
com.storedobject.iot.Consumption<P>
- All Implemented Interfaces:
Displayable
,StringFiller
,DBTransaction.NoHistory
,HasId
- Direct Known Subclasses:
DailyConsumption
,HourlyConsumption
,MonthlyConsumption
,WeeklyConsumption
,YearlyConsumption
public abstract class Consumption<P extends PeriodType>
extends StoredObject
implements DBTransaction.NoHistory
Represents consumption data associated with a specific resource, item, and a time period.
This is an abstract class that provides a framework for subclasses to define consumption records
over different periods, such as hourly, daily, weekly, monthly, or yearly.
The class enforces restrictions on setting certain attributes while not loading, and ensures data consistency and correctness through validations and relationships with related entities. Consumption values can also be updated and adjusted incrementally.
- Author:
- Syam
-
Field Summary
Fields inherited from class com.storedobject.core.StoredObject
logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Configures the specifiedColumns
instance by adding column definitions representing the fields of the Consumption class.double
Retrieves the consumption value.getItem()
Retrieves the associated item as anAbstractUnit
.Retrieves the unique identifier associated with the item in the consumption record.abstract int
Abstract method to retrieve the period associated with the consumption record.abstract String
Provides detailed information about the period associated with the consumption instance.Retrieves the period name of the consumption instance.abstract PeriodType
Retrieves the type of period associated with the consumption instance.Retrieves theResource
associated with the current object.Retrieves the resource identifier associated with this consumption entity.int
getYear()
Retrieves the year associated with the consumption record.abstract Consumption
<P> next()
Retrieves the next Consumption object in a sequence, if available.abstract Consumption
<P> previous()
Retrieves the previous instance of the Consumption object, typically representing the data for the preceding time period associated with the current object.void
setConsumption
(double consumption) Sets the consumption value for this instance.void
Sets the item identifier for the current object if allowed.void
setItem
(AbstractUnit item) Sets the item for this consumption instance using an AbstractUnit.void
setItem
(BigDecimal idValue) Sets the item identifier for the current object using the given BigDecimal value.void
setResource
(Id resourceId) Sets the resource by its identifier.void
setResource
(Resource resource) Sets the resource for this consumption.void
setResource
(BigDecimal idValue) Sets the resource of the object using the specified BigDecimal value.void
setYear
(int year) Sets the year for the consumption record.Converts the consumption record into a displayable string representation.void
Validates the data associated with the consumption record by ensuring that the specified item and resource are of the correct types and are properly set.Methods inherited from class com.storedobject.core.StoredObject
addLink, addLink, addLink, addLink, addLink, addLink, addLink, addLink, checkCurrency, checkCurrency, checkForDuplicate, checkForDuplicate, checkTimeZone, checkTransaction, clearObjectLinks, contemporary, copy, copy, count, count, count, count, count, count, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countLinks, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, countMasters, create, created, delete, delete, delete, deleted, directUpdate, equals, exists, exists, exists, exists, exists, existsFileData, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLink, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsLinks, existsMaster, existsMaster, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, existsMasters, family, family, family, fill, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, getAttachment, getAttachmentId, getChildren, getDeleted, getDeleted, getExistsCondition, getExistsCondition, getFileData, getFileData, getHistorical, getId, getKeyIndex, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getMaster, getNotExistsCondition, getNotExistsCondition, getParent, getParent, getParent, getParentId, getParentId, getParentId, getRelated, getRelated, getTransaction, getTransactionId, getTransactionIP, getUnique, getUniqueCondition, hashCode, inserted, isModified, isVirtual, list, list, list, list, list, list, list, list, list, list, list, list, list, listFileData, listFileData, listHistory, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listLinks, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listMasters, listTree, listTree, listTree, listTree, listViaQuery, listViaQuery, load, load, load, load, loaded, loading, makeNew, makeVirtual, migrate, moduleName, nextVersion, objectLink, objectLink, objectLink, objectLinks, objectLinks, old, person, previousVersion, previousVersion, query, query, query, query, query, query, query, query, query, query, query, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryLinks, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, queryMasters, reload, reload, reloaded, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeAllLinks, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeLink, removeReverseLinks, removeReverseLinks, save, save, save, save, save, save, save, save, save, save, save, save, save, save, saved, saving, setMaster, setRawValue, setTransaction, stringify, tableName, timestamp, toCode, toString, transacting, undelete, undelete, undeleted, updated, user, userId, validate, validateChildAttach, validateChildDetach, validateChildUpdate, validateDelete, validateInsert, validateParentAttach, validateParentDetach, validateParentUpdate, validateUndelete, validateUpdate, valueEquals
-
Constructor Details
-
Consumption
public Consumption()Default constructor for the Consumption class. Initializes an instance of the Consumption object.
-
-
Method Details
-
columns
Configures the specifiedColumns
instance by adding column definitions representing the fields of the Consumption class.- Parameters:
columns
- TheColumns
instance to which column definitions are added.- Adds a column named "Item" of type "id" to represent an identifier for items. - Adds a column named "Resource" of type "id" to represent an identifier for resources. - Adds a column named "Year" of type "int" to represent the year field. - Adds a column named "Consumption" of type "double precision" to represent the consumption field.
-
setItem
Sets the item identifier for the current object if allowed.- Parameters:
itemId
- The identifier of the item to set.- Throws:
Set_Not_Allowed
- if the itemId cannot be set due to current conditions.
-
setItem
Sets the item identifier for the current object using the given BigDecimal value. The BigDecimal value is used to create a new ID, which is then set as the item identifier.- Parameters:
idValue
- A BigDecimal value representing the identifier of the item to be set.
-
setItem
Sets the item for this consumption instance using an AbstractUnit. If the provided AbstractUnit is null, the item ID is also set to null. Otherwise, the item ID is set to the ID of the provided AbstractUnit.- Parameters:
item
- AbstractUnit instance whose ID will be set as the item ID, or null to clear the item ID.
-
getItemId
Retrieves the unique identifier associated with the item in the consumption record.- Returns:
- The identifier of the item as an
Id
.
-
getItem
Retrieves the associated item as anAbstractUnit
.- Returns:
- The associated
AbstractUnit
instance based on the item ID.
-
setResource
Sets the resource by its identifier. This method ensures that the resource identifier is only set under valid conditions. It throws an exception if the resource identifier is not permitted to be updated under the current state of the object.- Parameters:
resourceId
- The identifier of the resource to be set.- Throws:
Set_Not_Allowed
- If the resource identifier cannot be updated.
-
setResource
Sets the resource of the object using the specified BigDecimal value. The BigDecimal value is converted to an Id instance before setting.- Parameters:
idValue
- the BigDecimal value representing the ID of the resource to set
-
setResource
Sets the resource for this consumption. If the input resource is null, the resource ID is set to null.- Parameters:
resource
- The resource to be associated with this consumption object. If this is null, the resource ID will be set to null.
-
getResourceId
Retrieves the resource identifier associated with this consumption entity.- Returns:
- The identifier of the resource as an
Id
.
-
getResource
-
setYear
public void setYear(int year) Sets the year for the consumption record.- Parameters:
year
- The year value to set.
-
getYear
-
setConsumption
public void setConsumption(double consumption) Sets the consumption value for this instance.- Parameters:
consumption
- The consumption value to set, represented as a double.
-
getConsumption
-
validateData
Validates the data associated with the consumption record by ensuring that the specified item and resource are of the correct types and are properly set. Additionally, it invokes the superclass implementation for further validation.- Overrides:
validateData
in classStoredObject
- Parameters:
tm
- TheTransactionManager
instance that facilitates the verification of object types and enforces any validation rules for the transaction.- Throws:
Exception
- If any validation rule fails or the data is invalid.
-
getPeriodName
Retrieves the period name of the consumption instance. If the instance is of typeDailyConsumption
, the method returns "Day". For other subclasses, it derives the name from the class name, removing anything after and including "ly" in the class name.- Returns:
- The name of the period associated with the consumption instance. For DailyConsumption, it returns "Day". For other types, it derives the period name dynamically.
-
getPeriod
public abstract int getPeriod()Abstract method to retrieve the period associated with the consumption record. This is intended to be implemented by subclasses to define specific logic for determining the period.- Returns:
- The period as an integer, representing a time frame or interval linked to the consumption data.
-
getPeriodDetail
Provides detailed information about the period associated with the consumption instance.- Returns:
- A string representing the detailed period information.
-
toDisplay
Converts the consumption record into a displayable string representation.- Specified by:
toDisplay
in interfaceDisplayable
- Overrides:
toDisplay
in classStoredObject
- Returns:
- A string representation of the consumption record in the format: "Resource (Item) = Consumption (Year: [Yearly or Detailed Period Info])".
-
previous
Retrieves the previous instance of the Consumption object, typically representing the data for the preceding time period associated with the current object.- Returns:
- The previous Consumption object, or null if there is no prior consumption data.
-
next
Retrieves the next Consumption object in a sequence, if available. This method is abstract and must be implemented by subclasses to define the logic for fetching the next Consumption instance.- Returns:
- the next Consumption object, or null if no further object exists in the sequence.
-
getPeriodType
Retrieves the type of period associated with the consumption instance. The period type is expected to represent an interval such as HOURLY, DAILY, WEEKLY, MONTHLY, or YEARLY, as defined in thePeriodType
enum.- Returns:
- The
PeriodType
indicating the interval type for this consumption instance.
-