package net.pterodactylus.sone.core;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import net.pterodactylus.util.validation.EqualityValidator;
import net.pterodactylus.util.validation.IntegerRangeValidator;
import net.pterodactylus.util.validation.OrValidator;
-import net.pterodactylus.util.validation.Validation;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
* @return The Sone rescuer for the given Sone
*/
public SoneRescuer getSoneRescuer(Sone sone) {
- Validation.begin().isNotNull("Sone", sone).check().is("Local Sone", sone.isLocal()).check();
+ checkNotNull(sone, "sone must not be null");
+ checkArgument(sone.isLocal(), "sone must be local");
synchronized (sones) {
SoneRescuer soneRescuer = soneRescuers.get(sone);
if (soneRescuer == null) {
* @return {@code true} if the target Sone is trusted by the origin Sone
*/
public boolean isSoneTrusted(Sone origin, Sone target) {
- Validation.begin().isNotNull("Origin", origin).isNotNull("Target", target).check().isInstanceOf("Origin’s OwnIdentity", origin.getIdentity(), OwnIdentity.class).check();
+ checkNotNull(origin, "origin must not be null");
+ checkNotNull(target, "target must not be null");
+ checkArgument(origin.getIdentity() instanceof OwnIdentity, "origin’s identity must be an OwnIdentity");
return trustedIdentities.containsKey(origin.getIdentity()) && trustedIdentities.get(origin.getIdentity()).contains(target.getIdentity());
}
* @return All posts that have the given Sone as recipient
*/
public Set<Post> getDirectedPosts(Sone recipient) {
- Validation.begin().isNotNull("Recipient", recipient).check();
+ checkNotNull(recipient, "recipient must not be null");
Set<Post> directedPosts = new HashSet<Post>();
synchronized (posts) {
for (Post post : posts.values()) {
* The ID of the Sone to follow
*/
public void followSone(Sone sone, String soneId) {
- Validation.begin().isNotNull("Sone", sone).isNotNull("Sone ID", soneId).check();
+ checkNotNull(sone, "sone must not be null");
+ checkNotNull(soneId, "soneId must not be null");
Sone followedSone = getSone(soneId, true);
if (followedSone == null) {
logger.log(Level.INFO, String.format("Ignored Sone with invalid ID: %s", soneId));
* The Sone that should be followed
*/
public void followSone(Sone sone, Sone followedSone) {
- Validation.begin().isNotNull("Sone", sone).isNotNull("Followed Sone", followedSone).check();
+ checkNotNull(sone, "sone must not be null");
+ checkNotNull(followedSone, "followedSone must not be null");
sone.addFriend(followedSone.getId());
synchronized (soneFollowingTimes) {
if (!soneFollowingTimes.containsKey(followedSone)) {
* The ID of the Sone being unfollowed
*/
public void unfollowSone(Sone sone, String soneId) {
- Validation.begin().isNotNull("Sone", sone).isNotNull("Sone ID", soneId).check();
+ checkNotNull(sone, "sone must not be null");
+ checkNotNull(soneId, "soneId must not be null");
unfollowSone(sone, getSone(soneId, false));
}
* The Sone being unfollowed
*/
public void unfollowSone(Sone sone, Sone unfollowedSone) {
- Validation.begin().isNotNull("Sone", sone).isNotNull("Unfollowed Sone", unfollowedSone).check();
+ checkNotNull(sone, "sone must not be null");
+ checkNotNull(unfollowedSone, "unfollowedSone must not be null");
sone.removeFriend(unfollowedSone.getId());
boolean unfollowedSoneStillFollowed = false;
for (Sone localSone : getLocalSones()) {
* The trust value (from {@code -100} to {@code 100})
*/
public void setTrust(Sone origin, Sone target, int trustValue) {
- Validation.begin().isNotNull("Trust Origin", origin).check().isInstanceOf("Trust Origin", origin.getIdentity(), OwnIdentity.class).isNotNull("Trust Target", target).isLessOrEqual("Trust Value", trustValue, 100).isGreaterOrEqual("Trust Value", trustValue, -100).check();
+ checkNotNull(origin, "origin must not be null");
+ checkArgument(origin.getIdentity() instanceof OwnIdentity, "origin must be a local Sone");
+ checkNotNull(target, "target must not be null");
+ checkArgument((trustValue >= -100) && (trustValue <= 100), "trustValue must be within [-100, 100]");
webOfTrustUpdater.setTrust((OwnIdentity) origin.getIdentity(), target.getIdentity(), trustValue, preferences.getTrustComment());
}
* The trust target
*/
public void removeTrust(Sone origin, Sone target) {
- Validation.begin().isNotNull("Trust Origin", origin).isNotNull("Trust Target", target).check().isInstanceOf("Trust Origin Identity", origin.getIdentity(), OwnIdentity.class).check();
+ checkNotNull(origin, "origin must not be null");
+ checkNotNull(target, "target must not be null");
+ checkArgument(origin.getIdentity() instanceof OwnIdentity, "origin must be a local Sone");
webOfTrustUpdater.setTrust((OwnIdentity) origin.getIdentity(), target.getIdentity(), null, null);
}
* @return The created post
*/
public Post createPost(Sone sone, Sone recipient, long time, String text) {
- Validation.begin().isNotNull("Text", text).check().isGreater("Text Length", text.length(), 0).check();
+ checkNotNull(text, "text must not be null");
+ checkArgument(text.trim().length() > 0, "text must not be empty");
if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to create post for non-local Sone: %s", sone));
return null;
* @return The created reply
*/
public PostReply createReply(Sone sone, Post post, long time, String text) {
- Validation.begin().isNotNull("Text", text).check().isGreater("Text Length", text.trim().length(), 0).check();
+ checkNotNull(text, "text must not be null");
+ checkArgument(text.trim().length() > 0, "text must not be empty");
if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone));
return null;
* The album to remove
*/
public void deleteAlbum(Album album) {
- Validation.begin().isNotNull("Album", album).check().is("Local Sone", album.getSone().isLocal()).check();
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.getSone().isLocal(), "album’s Sone must be a local Sone");
if (!album.isEmpty()) {
return;
}
* @return The newly created image
*/
public Image createImage(Sone sone, Album album, TemporaryImage temporaryImage) {
- Validation.begin().isNotNull("Sone", sone).isNotNull("Album", album).isNotNull("Temporary Image", temporaryImage).check().is("Local Sone", sone.isLocal()).check().isEqual("Owner and Album Owner", sone, album.getSone()).check();
+ checkNotNull(sone, "sone must not be null");
+ checkNotNull(album, "album must not be null");
+ checkNotNull(temporaryImage, "temporaryImage must not be null");
+ checkArgument(sone.isLocal(), "sone must be a local Sone");
+ checkArgument(sone.equals(album.getSone()), "album must belong to the given Sone");
Image image = new Image(temporaryImage.getId()).setSone(sone).setCreationTime(System.currentTimeMillis());
album.addImage(image);
synchronized (images) {
* The image to delete
*/
public void deleteImage(Image image) {
- Validation.begin().isNotNull("Image", image).check().is("Local Sone", image.getSone().isLocal()).check();
+ checkNotNull(image, "image must not be null");
+ checkArgument(image.getSone().isLocal(), "image must belong to a local Sone");
deleteTemporaryImage(image.getId());
image.getAlbum().removeImage(image);
synchronized (images) {
* The temporary image to delete
*/
public void deleteTemporaryImage(TemporaryImage temporaryImage) {
- Validation.begin().isNotNull("Temporary Image", temporaryImage).check();
+ checkNotNull(temporaryImage, "temporaryImage must not be null");
deleteTemporaryImage(temporaryImage.getId());
}
* The ID of the temporary image to delete
*/
public void deleteTemporaryImage(String imageId) {
- Validation.begin().isNotNull("Temporary Image ID", imageId).check();
+ checkNotNull(imageId, "imageId must not be null");
synchronized (temporaryImages) {
temporaryImages.remove(imageId);
}
package net.pterodactylus.sone.core;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.TemporaryImage;
import net.pterodactylus.util.logging.Logging;
-import net.pterodactylus.util.validation.Validation;
/**
* The image inserter is responsible for inserting images using
* The image
*/
public void insertImage(TemporaryImage temporaryImage, Image image) {
- Validation.begin().isNotNull("Temporary Image", temporaryImage).isNotNull("Image", image).check().isEqual("Image IDs", image.getId(), temporaryImage.getId()).check();
+ checkNotNull(temporaryImage, "temporaryImage must not be null");
+ checkNotNull(image, "image must not be null");
+ checkArgument(image.getId().equals(temporaryImage.getId()), "image IDs must match");
try {
InsertToken insertToken = freenetInterface.new InsertToken(image);
insertTokens.put(image.getId(), insertToken);
package net.pterodactylus.sone.core;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import net.pterodactylus.sone.freenet.wot.WebOfTrustException;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.service.AbstractService;
-import net.pterodactylus.util.validation.Validation;
import com.google.inject.Inject;
*/
@SuppressWarnings("synthetic-access")
public WebOfTrustContextUpdateJob(OwnIdentity ownIdentity, String context) {
- Validation.begin().isNotNull("OwnIdentity", ownIdentity).isNotNull("Context", context).check();
- this.ownIdentity = ownIdentity;
- this.context = context;
+ this.ownIdentity = checkNotNull(ownIdentity, "ownIdentity must not be null");
+ this.context = checkNotNull(context, "context must not be null");
}
//
package net.pterodactylus.sone.data;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.UUID;
import net.pterodactylus.util.object.Default;
-import net.pterodactylus.util.validation.Validation;
import com.google.common.base.Function;
import com.google.common.base.Predicates;
* The ID of the album
*/
public Album(String id) {
- Validation.begin().isNotNull("Album ID", id).check();
- this.id = id;
+ this.id = checkNotNull(id, "id must not be null");
}
//
* @return This album
*/
public Album setSone(Sone sone) {
- Validation.begin().isNotNull("New Album Owner", sone).isEither("Old Album Owner", this.sone, null, sone).check();
+ checkNotNull(sone, "sone must not be null");
+ checkState((this.sone == null) || (this.sone.equals(sone)), "album owner must not already be set to some other Sone");
this.sone = sone;
return this;
}
* The album to add
*/
public void addAlbum(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).isEither("Old Album Parent", this.parent, null, album.parent).check();
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.getSone().equals(sone), "album must belong to the same Sone as this album");
+ checkState((this.parent == null) || (this.parent.equals(album.parent)), "album must not already be set to some other Sone");
album.setParent(this);
if (!albums.contains(album)) {
albums.add(album);
* The album to remove
*/
public void removeAlbum(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).isEqual("Album Parent", album.parent, this).check();
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.sone.equals(sone), "album must belong this album’s Sone");
+ checkArgument(equals(album.parent), "album must belong to this album");
albums.remove(album);
album.removeParent();
}
* <code>null</code> if the album did not change its place
*/
public Album moveAlbumUp(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).isEqual("Album Parent", album.parent, this).check();
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.sone.equals(sone), "album must belong to the same Sone as this album");
+ checkArgument(equals(album.parent), "album must belong to this album");
int oldIndex = albums.indexOf(album);
if (oldIndex <= 0) {
return null;
* <code>null</code> if the album did not change its place
*/
public Album moveAlbumDown(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).isEqual("Album Parent", album.parent, this).check();
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.sone.equals(sone), "album must belong to the same Sone as this album");
+ checkArgument(equals(album.parent), "album must belong to this album");
int oldIndex = albums.indexOf(album);
if ((oldIndex < 0) || (oldIndex >= (albums.size() - 1))) {
return null;
* The image to add
*/
public void addImage(Image image) {
- Validation.begin().isNotNull("Image", image).check().isNotNull("Image Owner", image.getSone()).check().isEqual("Image Owner", image.getSone(), sone).check();
+ checkNotNull(image, "image must not be null");
+ checkNotNull(image.getSone(), "image must have an owner");
+ checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
if (image.getAlbum() != null) {
image.getAlbum().removeImage(image);
}
* The image to remove
*/
public void removeImage(Image image) {
- Validation.begin().isNotNull("Image", image).check().isEqual("Image Owner", image.getSone(), sone).check();
+ checkNotNull(image, "image must not be null");
+ checkNotNull(image.getSone(), "image must have an owner");
+ checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
imageIds.remove(image.getId());
images.remove(image.getId());
if (image.getId().equals(albumImage)) {
* <code>null</code> if the image did not change its place
*/
public Image moveImageUp(Image image) {
- Validation.begin().isNotNull("Image", image).check().isEqual("Image Album", image.getAlbum(), this).isEqual("Album Owner", image.getAlbum().getSone(), sone).check();
+ checkNotNull(image, "image must not be null");
+ checkNotNull(image.getSone(), "image must have an owner");
+ checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
+ checkArgument(image.getAlbum().equals(this), "image must belong to this album");
int oldIndex = imageIds.indexOf(image.getId());
if (oldIndex <= 0) {
return null;
* <code>null</code> if the image did not change its place
*/
public Image moveImageDown(Image image) {
- Validation.begin().isNotNull("Image", image).check().isEqual("Image Album", image.getAlbum(), this).isEqual("Album Owner", image.getAlbum().getSone(), sone).check();
+ checkNotNull(image, "image must not be null");
+ checkNotNull(image.getSone(), "image must have an owner");
+ checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
+ checkArgument(image.getAlbum().equals(this), "image must belong to this album");
int oldIndex = imageIds.indexOf(image.getId());
if ((oldIndex == -1) || (oldIndex >= (imageIds.size() - 1))) {
return null;
* @return This album
*/
protected Album setParent(Album parent) {
- Validation.begin().isNotNull("Album Parent", parent).check();
- this.parent = parent;
+ this.parent = checkNotNull(parent, "parent must not be null");
return this;
}
* @return This album
*/
public Album setTitle(String title) {
- Validation.begin().isNotNull("Album Title", title).check();
- this.title = title;
+ this.title = checkNotNull(title, "title must not be null");
return this;
}
* @return This album
*/
public Album setDescription(String description) {
- Validation.begin().isNotNull("Album Description", description).check();
- this.description = description;
+ this.description = checkNotNull(description, "description must not be null");
return this;
}
package net.pterodactylus.sone.data;
-import java.util.UUID;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
-import net.pterodactylus.util.validation.Validation;
+import java.util.UUID;
/**
* Container for image metadata.
* The ID of the image
*/
public Image(String id) {
- Validation.begin().isNotNull("Image ID", id).check();
- this.id = id;
+ this.id = checkNotNull(id, "id must not be null");
}
//
* @return This image
*/
public Image setSone(Sone sone) {
- Validation.begin().isNotNull("New Image Owner", sone).isEither("Old Image Owner", this.sone, null, sone).check();
+ checkNotNull(sone, "sone must not be null");
+ checkArgument((this.sone == null) || this.sone.equals(sone), "sone must not already be set to another sone");
this.sone = sone;
return this;
}
* @return This image
*/
public Image setAlbum(Album album) {
- Validation.begin().isNotNull("New Album", album).check().isEqual("Album Owner and Image Owner", album.getSone(), getSone()).check();
+ checkNotNull(album, "album must not be null");
+ checkNotNull(album.getSone().equals(getSone()), "album must belong to the same Sone as this image");
this.album = album;
return this;
}
* @return This image
*/
public Image setKey(String key) {
- Validation.begin().isNotNull("New Image Key", key).isEither("Old Image Key", this.key, null, key).check();
+ checkNotNull(key, "key must not be null");
+ checkState((this.key == null) || this.key.equals(key), "key must not be already set to another key");
this.key = key;
return this;
}
* @return This image
*/
public Image setCreationTime(long creationTime) {
- Validation.begin().isGreater("New Image Creation Time", creationTime, 0).isEither("Old Image Creation Time", this.creationTime, 0L, creationTime).check();
+ checkArgument(creationTime > 0, "creationTime must be > 0");
+ checkState((this.creationTime == 0) || (this.creationTime == creationTime), "creationTime must not already be set");
this.creationTime = creationTime;
return this;
}
* @return This image
*/
public Image setWidth(int width) {
- Validation.begin().isGreater("New Image Width", width, 0).isEither("Old Image Width", this.width, 0, width).check();
+ checkArgument(width > 0, "width must be > 0");
+ checkState((this.width == 0) || (this.width == width), "width must not already be set to another width");
this.width = width;
return this;
}
* @return This image
*/
public Image setHeight(int height) {
- Validation.begin().isGreater("New Image Height", height, 0).isEither("Old Image Height", this.height, 0, height).check();
+ checkArgument(height > 0, "height must be > 0");
+ checkState((this.height == 0) || (this.height == height), "height must not already be set to another height");
this.height = height;
return this;
}
* @return This image
*/
public Image setTitle(String title) {
- Validation.begin().isNotNull("Image Title", title).check();
- this.title = title;
+ this.title = checkNotNull(title, "title must not be null");
return this;
}
* @return This image
*/
public Image setDescription(String description) {
- Validation.begin().isNotNull("Image Description", description).check();
- this.description = description;
+ this.description = checkNotNull(description, "description must not be null");
return this;
}
package net.pterodactylus.sone.data;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
-import net.pterodactylus.util.validation.Validation;
-
/**
* A profile stores personal information about a {@link Sone}. All information
* is optional and can be {@code null}.
this.avatar = null;
return this;
}
- Validation.begin().isEqual("Image Owner", avatar.getSone(), sone).check();
+ checkArgument(avatar.getSone().equals(sone), "avatar must belong to Sone");
this.avatar = avatar.getId();
return this;
}
* field with the given ID
*/
public Field getFieldById(String fieldId) {
- Validation.begin().isNotNull("Field ID", fieldId).check();
+ checkNotNull(fieldId, "fieldId must not be null");
for (Field field : fields) {
if (field.getId().equals(fieldId)) {
return field;
* if the name is not valid
*/
public Field addField(String fieldName) throws IllegalArgumentException {
- Validation.begin().isNotNull("Field Name", fieldName).check().isGreater("Field Name Length", fieldName.length(), 0).isNull("Field Name Unique", getFieldByName(fieldName)).check();
+ checkNotNull(fieldName, "fieldName must not be null");
+ checkArgument(fieldName.length() > 0, "fieldName must not be empty");
+ checkState(getFieldByName(fieldName) == null, "fieldName must be unique");
@SuppressWarnings("synthetic-access")
Field field = new Field().setName(fieldName);
fields.add(field);
* The field to move up
*/
public void moveFieldUp(Field field) {
- Validation.begin().isNotNull("Field", field).check().is("Field Existing", hasField(field)).isGreater("Field Index", getFieldIndex(field), 0).check();
+ 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");
int fieldIndex = getFieldIndex(field);
fields.remove(field);
fields.add(fieldIndex - 1, field);
* The field to move down
*/
public void moveFieldDown(Field field) {
- Validation.begin().isNotNull("Field", field).check().is("Field Existing", hasField(field)).isLess("Field Index", getFieldIndex(field), fields.size() - 1).check();
+ 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));
int fieldIndex = getFieldIndex(field);
fields.remove(field);
fields.add(fieldIndex + 1, field);
* The field to remove
*/
public void removeField(Field field) {
- Validation.begin().isNotNull("Field", field).check().is("Field Existing", hasField(field)).check();
+ checkNotNull(field, "field must not be null");
+ checkArgument(hasField(field), "field must belong to this profile");
fields.remove(field);
}
* The ID of the field
*/
private Field(String id) {
- Validation.begin().isNotNull("Field ID", id).check();
- this.id = id;
+ this.id = checkNotNull(id, "id must not be null");
}
/**
* @return This field
*/
public Field setName(String name) {
- Validation.begin().isNotNull("Field Name", name).check().is("Field Unique", (getFieldByName(name) == null) || equals(getFieldByName(name))).check();
+ checkNotNull(name, "name must not be null");
+ checkArgument(getFieldByName(name) == null, "name must be unique");
this.name = name;
return this;
}
package net.pterodactylus.sone.data;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import net.pterodactylus.sone.template.SoneAccessor;
import net.pterodactylus.util.logging.Logging;
-import net.pterodactylus.util.validation.Validation;
import com.google.common.base.Predicate;
* if {@code status} is {@code null}
*/
public Sone setStatus(SoneStatus status) {
- Validation.begin().isNotNull("Sone Status", status).check();
- this.status = status;
+ this.status = checkNotNull(status, "status must not be null");
return this;
}
* The album to add
*/
public void addAlbum(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).check();
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.getSone().equals(this), "album must belong to this Sone");
if (!albums.contains(album)) {
albums.add(album);
}
* The albums of this Sone
*/
public void setAlbums(Collection<? extends Album> albums) {
- Validation.begin().isNotNull("Albums", albums).check();
+ checkNotNull(albums, "albums must not be null");
this.albums.clear();
for (Album album : albums) {
addAlbum(album);
* The album to remove
*/
public void removeAlbum(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).check();
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.getSone().equals(this), "album must belong to this Sone");
albums.remove(album);
}
* <code>null</code> if the album did not change its place
*/
public Album moveAlbumUp(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).isNull("Album Parent", album.getParent()).check();
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.getSone().equals(this), "album must belong to this Sone");
+ checkArgument(album.getParent() == null, "album must not have a parent");
int oldIndex = albums.indexOf(album);
if (oldIndex <= 0) {
return null;
* <code>null</code> if the album did not change its place
*/
public Album moveAlbumDown(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).isNull("Album Parent", album.getParent()).check();
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.getSone().equals(this), "album must belong to this Sone");
+ checkArgument(album.getParent() == null, "album must not have a parent");
int oldIndex = albums.indexOf(album);
if ((oldIndex < 0) || (oldIndex >= (albums.size() - 1))) {
return null;
package net.pterodactylus.sone.data;
-import java.util.UUID;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
-import net.pterodactylus.util.validation.Validation;
+import java.util.UUID;
/**
* A temporary image stores an uploaded image in memory until it has been
* @return This temporary image
*/
public TemporaryImage setMimeType(String mimeType) {
- Validation.begin().isNotNull("MIME Type", mimeType).isNull("Previous MIME Type", this.mimeType).check();
+ checkNotNull(mimeType, "mimeType must not be null");
+ checkState(this.mimeType == null, "mime type must not already be set");
this.mimeType = mimeType;
return this;
}
* @return This temporary image
*/
public TemporaryImage setImageData(byte[] imageData) {
- Validation.begin().isNotNull("Image Data", imageData).isNull("Previous Image Data", this.imageData).check();
+ checkNotNull(imageData, "imageData must not be null");
+ checkState(this.imageData == null, "image data must not already be set");
this.imageData = imageData;
return this;
}
package net.pterodactylus.sone.fcp;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import net.pterodactylus.sone.freenet.fcp.Command.ErrorResponse;
import net.pterodactylus.sone.freenet.fcp.Command.Response;
import net.pterodactylus.util.logging.Logging;
-import net.pterodactylus.util.validation.Validation;
import com.google.inject.Inject;
* The action level for which full FCP access is required
*/
public void setFullAccessRequired(FullAccessRequired fullAccessRequired) {
- Validation.begin().isNotNull("FullAccessRequired", fullAccessRequired).check();
- this.fullAccessRequired = fullAccessRequired;
+ this.fullAccessRequired = checkNotNull(fullAccessRequired, "fullAccessRequired must not be null");
}
//
package net.pterodactylus.sone.freenet;
-import net.pterodactylus.util.validation.Validation;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import freenet.support.SimpleFieldSet;
/**
* The simple field set to build
*/
public SimpleFieldSetBuilder(SimpleFieldSet simpleFieldSet) {
- Validation.begin().isNotNull("Simple Field Set", simpleFieldSet).check();
- this.simpleFieldSet = simpleFieldSet;
+ this.simpleFieldSet = checkNotNull(simpleFieldSet, "simpleFieldSet must not be null");
}
/**
package net.pterodactylus.sone.notify;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import net.pterodactylus.sone.freenet.wot.Trust;
import net.pterodactylus.util.notify.Notification;
-import net.pterodactylus.util.validation.Validation;
/**
* Filter for {@link ListNotification}s.
* otherwise
*/
public static boolean isPostVisible(Sone sone, Post post) {
- Validation.begin().isNotNull("Post", post).check();
+ checkNotNull(post, "post must not be null");
Sone postSone = post.getSone();
if (postSone == null) {
return false;
* otherwise
*/
public static boolean isReplyVisible(Sone sone, PostReply reply) {
- Validation.begin().isNotNull("Reply", reply).check();
+ checkNotNull(reply, "reply must not be null");
Post post = reply.getPost();
if (post == null) {
return false;