Class 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) rating
      protected DataBank dataBank
      DataBank to store heterogeneous information
      protected String id
      User unique identifier
      protected SortedRatingList itemsRatings
      Items rated by the user
      protected double max
      Maximum (training) rating value
      protected double min
      Minimum (training) rating value
      protected int userIndex
      User index in the DataModel
    • Constructor Summary

      Constructors 
      Constructor Description
      User​(String id, int index)
      Creates a new instance of an user.
    • 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
    • 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 identifier
        index - 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 DataModel
        rating - 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