java.lang.Object
ch.bztf.m226blb1.Database.Entities.User

@Entity public class User extends Object
User entity for managing the user data and their posts.
Implementation Note:
The fields with a size limit will be trimmed.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    How many hours the user will be a valid cache.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a new User with the cachedSince set to the current time.
     
    User(Platform platform, @NotBlank @Size(min=1,max=65) String username, @NotBlank @Size(min=3,max=65) String name, @Size(min=0,max=255) String bio, @Size(min=0,max=255) String website, @NotBlank @Size(min=0,max=350) String profilePictureUrl, int followerCount, int followingCount, boolean isVerified, boolean isPrivate)
    Creates a new User with the cachedSince set to the current and all fields set.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addPost(@NonNull Post post)
    Adds a Post to the posts of the user.
    boolean
     
    Gets the posts of the user.
    int
     
    boolean
    Check if the cached user is still valid (not older than 12 hours)
    void
    Sets the bio to the given value.
    void
    Sets the name to the given value.
    void
    setPosts(@NonNull Set<Post> posts)
    Sets the posts of the user.
    void
    setProfilePictureUrl(String profilePictureUrl)
    Sets the profilePictureUrl to the given value.
    void
    setUsername(String username)
    Sets the username to the given value.
    void
    setWebsite(String website)
    Sets the website to the given value.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • User

      protected User()
      Creates a new User with the cachedSince set to the current time.
    • User

      public User(Platform platform, @NotBlank @Size(min=1,max=65) @NotBlank @Size(min=1,max=65) String username, @NotBlank @Size(min=3,max=65) @NotBlank @Size(min=3,max=65) String name, @Size(min=0,max=255) @Size(min=0,max=255) String bio, @Size(min=0,max=255) @Size(min=0,max=255) String website, @NotBlank @Size(min=0,max=350) @NotBlank @Size(min=0,max=350) String profilePictureUrl, int followerCount, int followingCount, boolean isVerified, boolean isPrivate)
      Creates a new User with the cachedSince set to the current and all fields set.
      Parameters:
      platform - the platform the user is on
      username - the username of the user
      name - the name of the user
      bio - the bio of the user
      website - the website of the user
      profilePictureUrl - the profile picture url of the user
      followerCount - the follower count of the user
      followingCount - the following count of the user
      isVerified - whether the user is verified
      isPrivate - whether the user is private
  • Method Details

    • isValidCache

      public boolean isValidCache()
      Check if the cached user is still valid (not older than 12 hours)
      Returns:
      true if the cached user is older than 12 hours
      API Note:
      This method will not be part of a response (JsonIgnore).
    • setUsername

      public void setUsername(String username)
      Sets the username to the given value.
      Parameters:
      username - the new username
      See Also:
    • setName

      public void setName(String name)
      Sets the name to the given value.
      Parameters:
      name - the new name
      See Also:
    • setBio

      public void setBio(String bio)
      Sets the bio to the given value.
      Parameters:
      bio - the new bio
      See Also:
    • setWebsite

      public void setWebsite(String website)
      Sets the website to the given value.
      Parameters:
      website - the new website
      See Also:
    • setProfilePictureUrl

      public void setProfilePictureUrl(String profilePictureUrl)
      Sets the profilePictureUrl to the given value.
      Parameters:
      profilePictureUrl - the new profile picture url
      See Also:
    • setPosts

      public void setPosts(@NonNull @NonNull Set<Post> posts)
      Sets the posts of the user.
      Parameters:
      posts - the new posts
      Implementation Note:
      This method will set the author of the posts to the current user. The old posts will be be garbage collected.
    • getPosts

      public Set<Post> getPosts()
      Gets the posts of the user.
      Returns:
      the posts
      Implementation Note:
      The method will create a new set if the posts is null.
    • addPost

      public void addPost(@NonNull @NonNull Post post)
      Adds a Post to the posts of the user.
      Parameters:
      post - the post to add
      Implementation Note:
      The method will create a new set if the posts is null.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object