Class WasteService
java.lang.Object
ntnu.idatt2016.v233.SmartMat.service.group.WasteService
Service for waste
- Version:
- 1.1
- Author:
- Anders, Pedro, Birk
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateWaste
(WasteRequest wasteRequest) Creates a new wasteOptional<double[]>
getCakeDiagram
(long groupId) Get the cake diagram for a group of waste.getCO2PerPerson
(long groupId) Calculates the annual average CO2 emissions per person in the specified group.Optional<double[]>
getLastMonth
(long groupId) Retrieve an optional array of doubles representing the amount of waste produced in each of the last 4 months for a given group.getLostMoney
(long groupId) Retrieves the lost money in the last month for the group with the given ID.getWasteByGroupId
(long groupId) Gets a waste by its group idgetWasteById
(long id) Gets a waste by its idgetWasteOfCategoryByGroupId
(long groupId, String categoryName) Returns an Optional containing a List of Waste objects for a specific category and group id, or an empty Optional if there are no wastes for that category and group id.boolean
isUserAssosiatedWithWaste
(String username, long wasteId) Checks if the user is assosiated with the waste their trying to retrive
-
Constructor Details
-
WasteService
public WasteService()
-
-
Method Details
-
createWaste
Creates a new waste- Parameters:
wasteRequest
- the waste to create- Returns:
- an optional containing the waste if it was created
-
getWasteById
Gets a waste by its id- Parameters:
id
- the id of the waste- Returns:
- an optional containing the waste if it exists
-
getWasteByGroupId
Gets a waste by its group id- Parameters:
groupId
- the id of the group- Returns:
- an optional containing the waste if it exists
-
getWasteOfCategoryByGroupId
Returns an Optional containing a List of Waste objects for a specific category and group id, or an empty Optional if there are no wastes for that category and group id.- Parameters:
groupId
- the ID of the group to search incategoryName
- the name of the category to search for- Returns:
- an Optional containing a List of Waste objects, or an empty Optional if there are no wastes for that category and group id
-
getCakeDiagram
Get the cake diagram for a group of waste.- Parameters:
groupId
- The ID of the group for which to retrieve the cake diagram.- Returns:
- An Optional containing an array of doubles representing the cake diagram for the group, or an empty Optional if the group is not found.
-
getLastMonth
Retrieve an optional array of doubles representing the amount of waste produced in each of the last 4 months for a given group.- Parameters:
groupId
- a long representing the id of the group whose waste production statistics are to be retrieved- Returns:
- an optional array of doubles representing the amount of waste produced in each of the last 4 months for the given group, or an empty optional if the group could not be found or no waste was produced in the last 4 months
-
getLostMoney
Retrieves the lost money in the last month for the group with the given ID.- Parameters:
groupId
- the ID of the group to retrieve the lost money for- Returns:
- an
Optional
containing the lost money if the group exists, or empty if it doesn't exist or there are no wastes in the last month
-
getCO2PerPerson
Calculates the annual average CO2 emissions per person in the specified group.- Parameters:
groupId
- the ID of the group for which to calculate CO2 emissions- Returns:
- an Optional containing the annual average CO2 emissions per person, or empty if the group has no users or does not exist
-
isUserAssosiatedWithWaste
Checks if the user is assosiated with the waste their trying to retrive- Parameters:
username
- the username of the userwasteId
- the id of the waste- Returns:
- true if the user is associated with the waste, false otherwise
-