Package es.upm.etsisi.cf4j.data
Class User
- java.lang.Object
-
- es.upm.etsisi.cf4j.data.User
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
TestUser
public class User extends Object implements Serializable
Defines a composition of an User. An user is composed by:- User unique identifier.
- User index in the DataModel which stores him or her.
- Array of items rated by the user.
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
User unique identifierprotected SortedRatingList
itemsRatings
Items rated by the userprotected double
max
Maximum (training) rating valueprotected double
min
Minimum (training) rating valueprotected int
userIndex
User index in the DataModel
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRating(int itemIndex, double rating)
Adds a new rating of the user to an item.int
findItem(int itemIndex)
Finds position of a user's rating given the index of the Item in the DataModel.DataBank
getDataBank()
Gets the DataBank instance that stores heterogeneous information related to the User.String
getId()
Returns the user unique identifierint
getItemAt(int pos)
Returns the index of the Item rated by the User at the given position.double
getMaxRating()
Gets the maximum rating of the userdouble
getMinRating()
Gets the minimum rating of the userint
getNumberOfRatings()
Gets the number of items rated by the userdouble
getRatingAt(int pos)
Returns the rating of the user to the item at the pos positiondouble
getRatingAverage()
Gets the average value of ratingsint
getUserIndex()
Return the user index inside the DataModel
-
-
-
Field Detail
-
id
protected String id
User unique identifier
-
userIndex
protected int userIndex
User 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
-
itemsRatings
protected SortedRatingList itemsRatings
Items rated by the user
-
-
Constructor Detail
-
User
public User(String id, int index)
Creates a new instance of an user. This constructor should not be used by developers.- Parameters:
id
- User unique identifierindex
- Index of the user in the Users' array of the DataModel
-
-
Method Detail
-
getDataBank
public DataBank getDataBank()
Gets the DataBank instance that stores heterogeneous information related to the User.- Returns:
- DataBank instance
-
getId
public String getId()
Returns the user unique identifier- Returns:
- User identifier
-
getUserIndex
public int getUserIndex()
Return the user index inside the DataModel- Returns:
- User index inside the DataModel
-
getItemAt
public int getItemAt(int pos)
Returns the index of the Item rated by the User at the given position.- Parameters:
pos
- Position- Returns:
- Index of the item in the Items' 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
-
findItem
public int findItem(int itemIndex)
Finds position of a user's rating given the index of the Item in the DataModel.- Parameters:
itemIndex
- Item index- Returns:
- Item position if the item has been rated by the user or -1 if do not
-
getNumberOfRatings
public int getNumberOfRatings()
Gets the number of items rated by the user- Returns:
- Number of ratings
-
addRating
public void addRating(int itemIndex, double rating)
Adds a new rating of the user to an 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:
itemIndex
- Item index which identifies an item in the DataModelrating
- Rating value
-
getMinRating
public double getMinRating()
Gets the minimum rating of the user- Returns:
- Minimum rating
-
getMaxRating
public double getMaxRating()
Gets the maximum rating of the user- Returns:
- Maximum rating
-
getRatingAverage
public double getRatingAverage()
Gets the average value of ratings- Returns:
- Rating average
-
-