Class User
java.lang.Object
ch.bztf.m226blb1.Database.Entities.User
User entity for managing the user data and their
posts
.- Implementation Note:
- The fields with a
size
limit will betrimmed
.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
How many hours the user will be a valid cache. -
Constructor Summary
ModifierConstructorDescriptionprotected
User()
Creates a newUser
with thecachedSince
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 newUser
with thecachedSince
set to the current and all fields set. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds aPost
to theposts
of the user.boolean
getPosts()
Gets theposts
of the user.int
hashCode()
boolean
Check if the cached user is still valid (not older than 12 hours)void
Sets thebio
to the given value.void
Sets thename
to the given value.void
Sets theposts
of the user.void
setProfilePictureUrl
(String profilePictureUrl) Sets theprofilePictureUrl
to the given value.void
setUsername
(String username) Sets theusername
to the given value.void
setWebsite
(String website) Sets thewebsite
to the given value.toString()
-
Field Details
-
CACHED_HOURS
public static final int CACHED_HOURSHow many hours the user will be a valid cache.- See Also:
-
-
Constructor Details
-
User
protected User()Creates a newUser
with thecachedSince
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 newUser
with thecachedSince
set to the current and all fields set.- Parameters:
platform
- the platform the user is onusername
- the username of the username
- the name of the userbio
- the bio of the userwebsite
- the website of the userprofilePictureUrl
- the profile picture url of the userfollowerCount
- the follower count of the userfollowingCount
- the following count of the userisVerified
- whether the user is verifiedisPrivate
- 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
Sets theusername
to the given value.- Parameters:
username
- the new username- See Also:
-
setName
Sets thename
to the given value.- Parameters:
name
- the new name- See Also:
-
setBio
Sets thebio
to the given value.- Parameters:
bio
- the new bio- See Also:
-
setWebsite
Sets thewebsite
to the given value.- Parameters:
website
- the new website- See Also:
-
setProfilePictureUrl
Sets theprofilePictureUrl
to the given value.- Parameters:
profilePictureUrl
- the new profile picture url- See Also:
-
setPosts
Sets theposts
of the user.- Parameters:
posts
- the new posts- Implementation Note:
- This method will set the
author
of the posts to the currentuser
. The old posts will be be garbage collected.
-
getPosts
Gets theposts
of the user.- Returns:
- the posts
- Implementation Note:
- The method will create a new set if the
posts
is null.
-
addPost
Adds aPost
to theposts
of the user.- Parameters:
post
- the post to add- Implementation Note:
- The method will create a new set if the
posts
is null.
-
equals
-
hashCode
public int hashCode() -
toString
-