Package es.upm.etsisi.cf4j.data
Class Item
- java.lang.Object
-
- es.upm.etsisi.cf4j.data.Item
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
TestItem
public class Item extends Object implements Serializable
Defines a composition of an Item. An item is composed by:- Item unique identifier.
- Item index in the DataModel which stores it.
- Array of ratings made by users.
It is not recommended that developers generate new instances of this class since this is a memory-structural class.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected double
average
Average (training) ratingprotected DataBank
dataBank
DataBank to store heterogeneous informationprotected String
id
Item unique identifierprotected int
itemIndex
Item index in the DataModelprotected double
max
Maximum (training) rating valueprotected double
min
Minimum (training) rating valueprotected SortedRatingList
usersRatings
Users that have rated the item
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRating(int userIndex, double rating)
Adds a new rating of an user to the item.int
findUser(int userIndex)
Finds position of a rating that an user has made to the item given the index of the User in the DataModel.DataBank
getDataBank()
Gets the DataBank instance that stores heterogeneous information related to the Item.String
getId()
Returns the item unique identifierint
getItemIndex()
Return the item index inside the DataModeldouble
getMaxRating()
Gets the maximum rating received by the item.double
getMinRating()
Gets the minimum rating received by the item.int
getNumberOfRatings()
Gets the number of ratings that the item have receiveddouble
getRatingAt(int pos)
Returns the rating of the user to the item at the pos positiondouble
getRatingAverage()
Gets the average value of ratingsint
getUserAt(int pos)
Returns the index of the User that have rated the Item at the given position
-
-
-
Field Detail
-
id
protected String id
Item unique identifier
-
itemIndex
protected int itemIndex
Item index in the DataModel
-
min
protected double min
Minimum (training) rating value
-
max
protected double max
Maximum (training) rating value
-
average
protected double average
Average (training) rating
-
dataBank
protected DataBank dataBank
DataBank to store heterogeneous information
-
usersRatings
protected SortedRatingList usersRatings
Users that have rated the item
-
-
Constructor Detail
-
Item
public Item(String id, int index)
Creates a new instance of an item. This constructor should not be used by developers.- Parameters:
id
- Item unique identifierindex
- Index of the item in the Items' array of the DataModel
-
-
Method Detail
-
getDataBank
public DataBank getDataBank()
Gets the DataBank instance that stores heterogeneous information related to the Item.- Returns:
- DataBank instance
-
getId
public String getId()
Returns the item unique identifier- Returns:
- Item identifier
-
getItemIndex
public int getItemIndex()
Return the item index inside the DataModel- Returns:
- Item index inside the DataModel
-
getUserAt
public int getUserAt(int pos)
Returns the index of the User that have rated the Item at the given position- Parameters:
pos
- Position- Returns:
- Index of the user in the Users' array of the DataModel
-
getRatingAt
public double getRatingAt(int pos)
Returns the rating of the user to the item at the pos position- Parameters:
pos
- Position- Returns:
- Rating at indicated position
-
findUser
public int findUser(int userIndex)
Finds position of a rating that an user has made to the item given the index of the User in the DataModel.- Parameters:
userIndex
- User index- Returns:
- User position if the item has been rated by the user or -1 if do not
-
getNumberOfRatings
public int getNumberOfRatings()
Gets the number of ratings that the item have received- Returns:
- Number of ratings
-
addRating
public void addRating(int userIndex, double rating)
Adds a new rating of an user to the item. You cannot overwrite an existing rating, otherwise this method will throws an IllegalArgumentException. It is not recommended to use this method, use DataModel.addRating(...) instead.- Parameters:
userIndex
- User index which identifies the specific user in the DataModelrating
- Rating value
-
getMinRating
public double getMinRating()
Gets the minimum rating received by the item.- Returns:
- Minimum rating
-
getMaxRating
public double getMaxRating()
Gets the maximum rating received by the item.- Returns:
- Maximum rating
-
getRatingAverage
public double getRatingAverage()
Gets the average value of ratings- Returns:
- Rating average
-
-