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
sizelimit will betrimmed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intHow many hours the user will be a valid cache. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedUser()Creates a newUserwith thecachedSinceset 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 newUserwith thecachedSinceset to the current and all fields set. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds aPostto thepostsof the user.booleangetPosts()Gets thepostsof the user.inthashCode()booleanCheck if the cached user is still valid (not older than 12 hours)voidSets thebioto the given value.voidSets thenameto the given value.voidSets thepostsof the user.voidsetProfilePictureUrl(String profilePictureUrl) Sets theprofilePictureUrlto the given value.voidsetUsername(String username) Sets theusernameto the given value.voidsetWebsite(String website) Sets thewebsiteto 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 newUserwith thecachedSinceset 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 newUserwith thecachedSinceset 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 theusernameto the given value.- Parameters:
username- the new username- See Also:
-
setName
Sets thenameto the given value.- Parameters:
name- the new name- See Also:
-
setBio
Sets thebioto the given value.- Parameters:
bio- the new bio- See Also:
-
setWebsite
Sets thewebsiteto the given value.- Parameters:
website- the new website- See Also:
-
setProfilePictureUrl
Sets theprofilePictureUrlto the given value.- Parameters:
profilePictureUrl- the new profile picture url- See Also:
-
setPosts
Sets thepostsof the user.- Parameters:
posts- the new posts- Implementation Note:
- This method will set the
authorof the posts to the currentuser. The old posts will be be garbage collected.
-
getPosts
Gets thepostsof the user.- Returns:
- the posts
- Implementation Note:
- The method will create a new set if the
postsis null.
-
addPost
Adds aPostto thepostsof the user.- Parameters:
post- the post to add- Implementation Note:
- The method will create a new set if the
postsis null.
-
equals
-
hashCode
public int hashCode() -
toString
-