From: David ‘Bombe’ Roden Date: Wed, 15 Feb 2017 06:45:14 +0000 (+0100) Subject: Add some nullability annotations to Sone and profile X-Git-Tag: 0.9.7^2~292 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=acfc86d839d5a8b8c75b0198f48dd12e10128c65;p=Sone.git Add some nullability annotations to Sone and profile --- diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java index 0f9b8ff..a0ebeba 100644 --- a/src/main/java/net/pterodactylus/sone/data/Profile.java +++ b/src/main/java/net/pterodactylus/sone/data/Profile.java @@ -26,6 +26,9 @@ import java.util.Collections; import java.util.List; import java.util.UUID; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; @@ -80,7 +83,7 @@ public class Profile implements Fingerprintable { * @param profile * The profile to copy */ - public Profile(Profile profile) { + public Profile(@Nonnull Profile profile) { this.sone = profile.sone; this.firstName = profile.firstName; this.middleName = profile.middleName; @@ -101,6 +104,7 @@ public class Profile implements Fingerprintable { * * @return The Sone this profile belongs to */ + @Nonnull public Sone getSone() { return sone; } @@ -110,6 +114,7 @@ public class Profile implements Fingerprintable { * * @return The first name */ + @Nullable public String getFirstName() { return firstName; } @@ -121,7 +126,8 @@ public class Profile implements Fingerprintable { * The first name to set * @return This profile (for method chaining) */ - public Profile setFirstName(String firstName) { + @Nonnull + public Profile setFirstName(@Nullable String firstName) { this.firstName = firstName; return this; } @@ -131,6 +137,7 @@ public class Profile implements Fingerprintable { * * @return The middle name */ + @Nullable public String getMiddleName() { return middleName; } @@ -142,7 +149,8 @@ public class Profile implements Fingerprintable { * The middle name to set * @return This profile (for method chaining) */ - public Profile setMiddleName(String middleName) { + @Nonnull + public Profile setMiddleName(@Nullable String middleName) { this.middleName = middleName; return this; } @@ -152,6 +160,7 @@ public class Profile implements Fingerprintable { * * @return The last name */ + @Nullable public String getLastName() { return lastName; } @@ -163,7 +172,8 @@ public class Profile implements Fingerprintable { * The last name to set * @return This profile (for method chaining) */ - public Profile setLastName(String lastName) { + @Nonnull + public Profile setLastName(@Nullable String lastName) { this.lastName = lastName; return this; } @@ -173,6 +183,7 @@ public class Profile implements Fingerprintable { * * @return The day of the birth date (from 1 to 31) */ + @Nullable public Integer getBirthDay() { return birthDay; } @@ -184,7 +195,8 @@ public class Profile implements Fingerprintable { * The day of the birth date (from 1 to 31) * @return This profile (for method chaining) */ - public Profile setBirthDay(Integer birthDay) { + @Nonnull + public Profile setBirthDay(@Nullable Integer birthDay) { this.birthDay = birthDay; return this; } @@ -194,6 +206,7 @@ public class Profile implements Fingerprintable { * * @return The month of the birth date (from 1 to 12) */ + @Nullable public Integer getBirthMonth() { return birthMonth; } @@ -205,7 +218,8 @@ public class Profile implements Fingerprintable { * The month of the birth date (from 1 to 12) * @return This profile (for method chaining) */ - public Profile setBirthMonth(Integer birthMonth) { + @Nonnull + public Profile setBirthMonth(@Nullable Integer birthMonth) { this.birthMonth = birthMonth; return this; } @@ -215,6 +229,7 @@ public class Profile implements Fingerprintable { * * @return The year of the birth date */ + @Nullable public Integer getBirthYear() { return birthYear; } @@ -225,6 +240,7 @@ public class Profile implements Fingerprintable { * @return The ID of the currently selected avatar image, or {@code null} if * no avatar is selected. */ + @Nullable public String getAvatar() { return avatar; } @@ -237,7 +253,8 @@ public class Profile implements Fingerprintable { * image. * @return This Sone */ - public Profile setAvatar(Image avatar) { + @Nonnull + public Profile setAvatar(@Nullable Image avatar) { if (avatar == null) { this.avatar = null; return this; @@ -254,7 +271,8 @@ public class Profile implements Fingerprintable { * The year of the birth date * @return This profile (for method chaining) */ - public Profile setBirthYear(Integer birthYear) { + @Nonnull + public Profile setBirthYear(@Nullable Integer birthYear) { this.birthYear = birthYear; return this; } @@ -264,6 +282,7 @@ public class Profile implements Fingerprintable { * * @return The fields of this profile */ + @Nonnull public List getFields() { return new ArrayList(fields); } @@ -275,7 +294,7 @@ public class Profile implements Fingerprintable { * The field to check for * @return {@code true} if this profile contains the field, false otherwise */ - public boolean hasField(Field field) { + public boolean hasField(@Nonnull Field field) { return fields.contains(field); } @@ -287,7 +306,8 @@ public class Profile implements Fingerprintable { * @return The field, or {@code null} if this profile does not contain a * field with the given ID */ - public Field getFieldById(String fieldId) { + @Nullable + public Field getFieldById(@Nonnull String fieldId) { checkNotNull(fieldId, "fieldId must not be null"); for (Field field : fields) { if (field.getId().equals(fieldId)) { @@ -305,7 +325,8 @@ public class Profile implements Fingerprintable { * @return The field, or {@code null} if this profile does not contain a * field with the given name */ - public Field getFieldByName(String fieldName) { + @Nullable + public Field getFieldByName(@Nonnull String fieldName) { for (Field field : fields) { if (field.getName().equals(fieldName)) { return field; @@ -323,7 +344,8 @@ public class Profile implements Fingerprintable { * @throws IllegalArgumentException * if the name is not valid */ - public Field addField(String fieldName) throws IllegalArgumentException { + @Nonnull + public Field addField(@Nonnull String fieldName) throws IllegalArgumentException { checkNotNull(fieldName, "fieldName must not be null"); if (fieldName.length() == 0) { throw new EmptyFieldName(); @@ -345,7 +367,7 @@ public class Profile implements Fingerprintable { * @param field * The field to move up */ - public void moveFieldUp(Field field) { + public void moveFieldUp(@Nonnull Field field) { checkNotNull(field, "field must not be null"); checkArgument(hasField(field), "field must belong to this profile"); checkArgument(getFieldIndex(field) > 0, "field index must be > 0"); @@ -362,7 +384,7 @@ public class Profile implements Fingerprintable { * @param field * The field to move down */ - public void moveFieldDown(Field field) { + public void moveFieldDown(@Nonnull Field field) { checkNotNull(field, "field must not be null"); checkArgument(hasField(field), "field must belong to this profile"); checkArgument(getFieldIndex(field) < fields.size() - 1, "field index must be < " + (fields.size() - 1)); @@ -377,7 +399,7 @@ public class Profile implements Fingerprintable { * @param field * The field to remove */ - public void removeField(Field field) { + public void removeField(@Nonnull Field field) { checkNotNull(field, "field must not be null"); checkArgument(hasField(field), "field must belong to this profile"); fields.remove(field); @@ -395,7 +417,7 @@ public class Profile implements Fingerprintable { * @return The index of the field, or {@code -1} if there is no field with * the given name */ - private int getFieldIndex(Field field) { + private int getFieldIndex(@Nonnull Field field) { return fields.indexOf(field); } @@ -470,7 +492,7 @@ public class Profile implements Fingerprintable { * @param id * The ID of the field */ - private Field(String id) { + private Field(@Nonnull String id) { this.id = checkNotNull(id, "id must not be null"); } @@ -479,6 +501,7 @@ public class Profile implements Fingerprintable { * * @return The ID of this field */ + @Nonnull public String getId() { return id; } @@ -488,6 +511,7 @@ public class Profile implements Fingerprintable { * * @return The name of this field */ + @Nonnull public String getName() { return name; } @@ -501,7 +525,8 @@ public class Profile implements Fingerprintable { * The new name of this field * @return This field */ - public Field setName(String name) { + @Nonnull + public Field setName(@Nonnull String name) { checkNotNull(name, "name must not be null"); checkArgument(getFieldByName(name) == null, "name must be unique"); this.name = name; @@ -513,6 +538,7 @@ public class Profile implements Fingerprintable { * * @return The value of this field */ + @Nullable public String getValue() { return value; } @@ -526,7 +552,8 @@ public class Profile implements Fingerprintable { * The new value of this field * @return This field */ - public Field setValue(String value) { + @Nonnull + public Field setValue(@Nullable String value) { this.value = value; return this; } diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 777660f..258fb4c 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -169,6 +169,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * * @return The identity of this Sone */ + @Nonnull Identity getIdentity(); /** @@ -176,6 +177,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * * @return The name of this Sone */ + @Nonnull String getName(); /** @@ -190,6 +192,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * * @return The request URI of this Sone */ + @Nonnull FreenetURI getRequestUri(); /** @@ -197,6 +200,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * * @return The insert URI of this Sone */ + @Nullable FreenetURI getInsertUri(); /** @@ -230,6 +234,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * The time of the update (in milliseconds since Jan 1, 1970 UTC) * @return This Sone (for method chaining) */ + @Nonnull Sone setTime(long time); /** @@ -237,6 +242,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * * @return The status of this Sone */ + @Nonnull SoneStatus getStatus(); /** @@ -248,7 +254,8 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * @throws IllegalArgumentException * if {@code status} is {@code null} */ - Sone setStatus(SoneStatus status); + @Nonnull + Sone setStatus(@Nonnull SoneStatus status); /** * Returns a copy of the profile. If you want to update values in the profile @@ -257,6 +264,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * * @return A copy of the profile */ + @Nonnull Profile getProfile(); /** @@ -267,13 +275,14 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * @param profile * The profile to set */ - void setProfile(Profile profile); + void setProfile(@Nonnull Profile profile); /** * Returns the client used by this Sone. * * @return The client used by this Sone, or {@code null} */ + @Nullable Client getClient(); /** @@ -283,7 +292,8 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * The client used by this Sone, or {@code null} * @return This Sone (for method chaining) */ - Sone setClient(Client client); + @Nonnull + Sone setClient(@Nullable Client client); /** * Returns whether this Sone is known. @@ -299,6 +309,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * {@code true} if this Sone is known, {@code false} otherwise * @return This Sone */ + @Nonnull Sone setKnown(boolean known); /** @@ -306,6 +317,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * * @return The friend Sones of this Sone */ + @Nonnull Collection getFriends(); /** @@ -316,13 +328,14 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * @return {@code true} if this Sone has the given Sone as a friend, {@code * false} otherwise */ - boolean hasFriend(String friendSoneId); + boolean hasFriend(@Nonnull String friendSoneId); /** * Returns the list of posts of this Sone, sorted by time, newest first. * * @return All posts of this Sone */ + @Nonnull List getPosts(); /** @@ -332,7 +345,8 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * The new (and only) posts of this Sone * @return This Sone (for method chaining) */ - Sone setPosts(Collection posts); + @Nonnull + Sone setPosts(@Nonnull Collection posts); /** * Adds the given post to this Sone. The post will not be added if its {@link @@ -341,7 +355,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * @param post * The post to add */ - void addPost(Post post); + void addPost(@Nonnull Post post); /** * Removes the given post from this Sone. @@ -349,13 +363,14 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * @param post * The post to remove */ - void removePost(Post post); + void removePost(@Nonnull Post post); /** * Returns all replies this Sone made. * * @return All replies this Sone made */ + @Nonnull Set getReplies(); /** @@ -365,7 +380,8 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * The new (and only) replies of this Sone * @return This Sone (for method chaining) */ - Sone setReplies(Collection replies); + @Nonnull + Sone setReplies(@Nonnull Collection replies); /** * Adds a reply to this Sone. If the given reply was not made by this Sone, @@ -374,7 +390,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * @param reply * The reply to add */ - void addReply(PostReply reply); + void addReply(@Nonnull PostReply reply); /** * Removes a reply from this Sone. @@ -382,13 +398,14 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * @param reply * The reply to remove */ - void removeReply(PostReply reply); + void removeReply(@Nonnull PostReply reply); /** * Returns the IDs of all liked posts. * * @return All liked posts’ IDs */ + @Nonnull Set getLikedPostIds(); /** @@ -398,7 +415,8 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * All liked posts’ IDs * @return This Sone (for method chaining) */ - Sone setLikePostIds(Set likedPostIds); + @Nonnull + Sone setLikePostIds(@Nonnull Set likedPostIds); /** * Checks whether the given post ID is liked by this Sone. @@ -408,7 +426,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * @return {@code true} if this Sone likes the given post, {@code false} * otherwise */ - boolean isLikedPostId(String postId); + boolean isLikedPostId(@Nonnull String postId); /** * Adds the given post ID to the list of posts this Sone likes. @@ -417,7 +435,8 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * The ID of the post * @return This Sone (for method chaining) */ - Sone addLikedPostId(String postId); + @Nonnull + Sone addLikedPostId(@Nonnull String postId); /** * Removes the given post ID from the list of posts this Sone likes. @@ -426,13 +445,15 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * The ID of the post * @return This Sone (for method chaining) */ - Sone removeLikedPostId(String postId); + @Nonnull + Sone removeLikedPostId(@Nonnull String postId); /** * Returns the IDs of all liked replies. * * @return All liked replies’ IDs */ + @Nonnull Set getLikedReplyIds(); /** @@ -442,7 +463,8 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * All liked replies’ IDs * @return This Sone (for method chaining) */ - Sone setLikeReplyIds(Set likedReplyIds); + @Nonnull + Sone setLikeReplyIds(@Nonnull Set likedReplyIds); /** * Checks whether the given reply ID is liked by this Sone. @@ -452,7 +474,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * @return {@code true} if this Sone likes the given reply, {@code false} * otherwise */ - boolean isLikedReplyId(String replyId); + boolean isLikedReplyId(@Nonnull String replyId); /** * Adds the given reply ID to the list of replies this Sone likes. @@ -461,7 +483,8 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * The ID of the reply * @return This Sone (for method chaining) */ - Sone addLikedReplyId(String replyId); + @Nonnull + Sone addLikedReplyId(@Nonnull String replyId); /** * Removes the given post ID from the list of replies this Sone likes. @@ -470,13 +493,15 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * The ID of the reply * @return This Sone (for method chaining) */ - Sone removeLikedReplyId(String replyId); + @Nonnull + Sone removeLikedReplyId(@Nonnull String replyId); /** * Returns the root album that contains all visible albums of this Sone. * * @return The root album of this Sone */ + @Nonnull Album getRootAlbum(); /** @@ -484,6 +509,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * * @return The options of this Sone */ + @Nonnull SoneOptions getOptions(); /** @@ -493,6 +519,6 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * The options of this Sone */ /* TODO - remove this method again, maybe add an option provider */ - void setOptions(SoneOptions options); + void setOptions(@Nonnull SoneOptions options); } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java index 04a5bcc..439f4c9 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java @@ -31,6 +31,9 @@ import java.util.concurrent.CopyOnWriteArraySet; import java.util.logging.Level; import java.util.logging.Logger; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Client; import net.pterodactylus.sone.data.Post; @@ -134,6 +137,7 @@ public class SoneImpl implements Sone { * * @return The identity of this Sone */ + @Nonnull public String getId() { return id; } @@ -143,6 +147,7 @@ public class SoneImpl implements Sone { * * @return The identity of this Sone */ + @Nonnull public Identity getIdentity() { return identity; } @@ -152,6 +157,7 @@ public class SoneImpl implements Sone { * * @return The name of this Sone */ + @Nonnull public String getName() { return (identity != null) ? identity.getNickname() : null; } @@ -170,6 +176,7 @@ public class SoneImpl implements Sone { * * @return The request URI of this Sone */ + @Nonnull public FreenetURI getRequestUri() { try { return new FreenetURI(getIdentity().getRequestUri()) @@ -189,6 +196,7 @@ public class SoneImpl implements Sone { * * @return The insert URI of this Sone */ + @Nullable public FreenetURI getInsertUri() { if (!isLocal()) { return null; @@ -244,6 +252,7 @@ public class SoneImpl implements Sone { * The time of the update (in milliseconds since Jan 1, 1970 UTC) * @return This Sone (for method chaining) */ + @Nonnull public Sone setTime(long time) { this.time = time; return this; @@ -254,6 +263,7 @@ public class SoneImpl implements Sone { * * @return The status of this Sone */ + @Nonnull public SoneStatus getStatus() { return status; } @@ -267,7 +277,8 @@ public class SoneImpl implements Sone { * @throws IllegalArgumentException * if {@code status} is {@code null} */ - public Sone setStatus(SoneStatus status) { + @Nonnull + public Sone setStatus(@Nonnull SoneStatus status) { this.status = checkNotNull(status, "status must not be null"); return this; } @@ -279,6 +290,7 @@ public class SoneImpl implements Sone { * * @return A copy of the profile */ + @Nonnull public Profile getProfile() { return new Profile(profile); } @@ -291,7 +303,7 @@ public class SoneImpl implements Sone { * @param profile * The profile to set */ - public void setProfile(Profile profile) { + public void setProfile(@Nonnull Profile profile) { this.profile = new Profile(profile); } @@ -300,6 +312,7 @@ public class SoneImpl implements Sone { * * @return The client used by this Sone, or {@code null} */ + @Nullable public Client getClient() { return client; } @@ -311,7 +324,8 @@ public class SoneImpl implements Sone { * The client used by this Sone, or {@code null} * @return This Sone (for method chaining) */ - public Sone setClient(Client client) { + @Nonnull + public Sone setClient(@Nullable Client client) { this.client = client; return this; } @@ -332,6 +346,7 @@ public class SoneImpl implements Sone { * {@code true} if this Sone is known, {@code false} otherwise * @return This Sone */ + @Nonnull public Sone setKnown(boolean known) { this.known = known; return this; @@ -342,6 +357,7 @@ public class SoneImpl implements Sone { * * @return The friend Sones of this Sone */ + @Nonnull public Collection getFriends() { return database.getFriends(this); } @@ -354,7 +370,7 @@ public class SoneImpl implements Sone { * @return {@code true} if this Sone has the given Sone as a friend, {@code * false} otherwise */ - public boolean hasFriend(String friendSoneId) { + public boolean hasFriend(@Nonnull String friendSoneId) { return database.isFriend(this, friendSoneId); } @@ -363,6 +379,7 @@ public class SoneImpl implements Sone { * * @return All posts of this Sone */ + @Nonnull public List getPosts() { List sortedPosts; synchronized (this) { @@ -379,7 +396,8 @@ public class SoneImpl implements Sone { * The new (and only) posts of this Sone * @return This Sone (for method chaining) */ - public Sone setPosts(Collection posts) { + @Nonnull + public Sone setPosts(@Nonnull Collection posts) { synchronized (this) { this.posts.clear(); this.posts.addAll(posts); @@ -394,7 +412,7 @@ public class SoneImpl implements Sone { * @param post * The post to add */ - public void addPost(Post post) { + public void addPost(@Nonnull Post post) { if (post.getSone().equals(this) && posts.add(post)) { logger.log(Level.FINEST, String.format("Adding %s to “%s”.", post, getName())); } @@ -406,7 +424,7 @@ public class SoneImpl implements Sone { * @param post * The post to remove */ - public void removePost(Post post) { + public void removePost(@Nonnull Post post) { if (post.getSone().equals(this)) { posts.remove(post); } @@ -417,6 +435,7 @@ public class SoneImpl implements Sone { * * @return All replies this Sone made */ + @Nonnull public Set getReplies() { return Collections.unmodifiableSet(replies); } @@ -428,7 +447,8 @@ public class SoneImpl implements Sone { * The new (and only) replies of this Sone * @return This Sone (for method chaining) */ - public Sone setReplies(Collection replies) { + @Nonnull + public Sone setReplies(@Nonnull Collection replies) { this.replies.clear(); this.replies.addAll(replies); return this; @@ -441,7 +461,7 @@ public class SoneImpl implements Sone { * @param reply * The reply to add */ - public void addReply(PostReply reply) { + public void addReply(@Nonnull PostReply reply) { if (reply.getSone().equals(this)) { replies.add(reply); } @@ -453,7 +473,7 @@ public class SoneImpl implements Sone { * @param reply * The reply to remove */ - public void removeReply(PostReply reply) { + public void removeReply(@Nonnull PostReply reply) { if (reply.getSone().equals(this)) { replies.remove(reply); } @@ -464,6 +484,7 @@ public class SoneImpl implements Sone { * * @return All liked posts’ IDs */ + @Nonnull public Set getLikedPostIds() { return Collections.unmodifiableSet(likedPostIds); } @@ -475,7 +496,8 @@ public class SoneImpl implements Sone { * All liked posts’ IDs * @return This Sone (for method chaining) */ - public Sone setLikePostIds(Set likedPostIds) { + @Nonnull + public Sone setLikePostIds(@Nonnull Set likedPostIds) { this.likedPostIds.clear(); this.likedPostIds.addAll(likedPostIds); return this; @@ -489,7 +511,7 @@ public class SoneImpl implements Sone { * @return {@code true} if this Sone likes the given post, {@code false} * otherwise */ - public boolean isLikedPostId(String postId) { + public boolean isLikedPostId(@Nonnull String postId) { return likedPostIds.contains(postId); } @@ -500,7 +522,8 @@ public class SoneImpl implements Sone { * The ID of the post * @return This Sone (for method chaining) */ - public Sone addLikedPostId(String postId) { + @Nonnull + public Sone addLikedPostId(@Nonnull String postId) { likedPostIds.add(postId); return this; } @@ -512,7 +535,8 @@ public class SoneImpl implements Sone { * The ID of the post * @return This Sone (for method chaining) */ - public Sone removeLikedPostId(String postId) { + @Nonnull + public Sone removeLikedPostId(@Nonnull String postId) { likedPostIds.remove(postId); return this; } @@ -522,6 +546,7 @@ public class SoneImpl implements Sone { * * @return All liked replies’ IDs */ + @Nonnull public Set getLikedReplyIds() { return Collections.unmodifiableSet(likedReplyIds); } @@ -533,7 +558,8 @@ public class SoneImpl implements Sone { * All liked replies’ IDs * @return This Sone (for method chaining) */ - public Sone setLikeReplyIds(Set likedReplyIds) { + @Nonnull + public Sone setLikeReplyIds(@Nonnull Set likedReplyIds) { this.likedReplyIds.clear(); this.likedReplyIds.addAll(likedReplyIds); return this; @@ -547,7 +573,7 @@ public class SoneImpl implements Sone { * @return {@code true} if this Sone likes the given reply, {@code false} * otherwise */ - public boolean isLikedReplyId(String replyId) { + public boolean isLikedReplyId(@Nonnull String replyId) { return likedReplyIds.contains(replyId); } @@ -558,7 +584,8 @@ public class SoneImpl implements Sone { * The ID of the reply * @return This Sone (for method chaining) */ - public Sone addLikedReplyId(String replyId) { + @Nonnull + public Sone addLikedReplyId(@Nonnull String replyId) { likedReplyIds.add(replyId); return this; } @@ -570,7 +597,8 @@ public class SoneImpl implements Sone { * The ID of the reply * @return This Sone (for method chaining) */ - public Sone removeLikedReplyId(String replyId) { + @Nonnull + public Sone removeLikedReplyId(@Nonnull String replyId) { likedReplyIds.remove(replyId); return this; } @@ -580,6 +608,7 @@ public class SoneImpl implements Sone { * * @return The root album of this Sone */ + @Nonnull public Album getRootAlbum() { return rootAlbum; } @@ -589,6 +618,7 @@ public class SoneImpl implements Sone { * * @return The options of this Sone */ + @Nonnull public SoneOptions getOptions() { return options; } @@ -600,7 +630,7 @@ public class SoneImpl implements Sone { * The options of this Sone */ /* TODO - remove this method again, maybe add an option provider */ - public void setOptions(SoneOptions options) { + public void setOptions(@Nonnull SoneOptions options) { this.options = options; } diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt b/src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt index dada6eb..4549641 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt @@ -17,6 +17,6 @@ inline fun bind(implementation: T): Module = inline fun bindMock(): Module = Module { it!!.bind(T::class.java).toInstance(mock()) } -inline fun whenever(methodCall: T) = Mockito.`when`(methodCall) +inline fun whenever(methodCall: T) = Mockito.`when`(methodCall)!! inline fun OngoingStubbing.thenReturnMock(): OngoingStubbing = this.thenReturn(mock()) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt index 36c83b7..0fb6cca 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt @@ -124,7 +124,7 @@ class EditProfilePageTest : WebPageTest() { fun `post request with field value saves profile and redirects back to profile edit page`() { val field = profile.addField("name") field.value = "old" - verifySingleFieldCanBeChanged("field-${field.id}", "new") { profile.getFieldByName("name").value } + verifySingleFieldCanBeChanged("field-${field.id}", "new") { profile.getFieldByName("name")!!.value } } @Test @@ -132,7 +132,7 @@ class EditProfilePageTest : WebPageTest() { val field = profile.addField("name") field.value = "old" addHttpRequestHeader("Host", "www.te.st") - verifySingleFieldCanBeChanged("field-${field.id}", "http://www.te.st/KSK@GPL.txt", "KSK@GPL.txt") { profile.getFieldByName("name").value } + verifySingleFieldCanBeChanged("field-${field.id}", "http://www.te.st/KSK@GPL.txt", "KSK@GPL.txt") { profile.getFieldByName("name")!!.value } } @Test