/*
- * Sone - Sone.java - Copyright © 2010–2012 David Roden
+ * Sone - Sone.java - Copyright © 2010–2013 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
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 java.util.logging.Level;
import java.util.logging.Logger;
-import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.core.Options;
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import net.pterodactylus.sone.template.SoneAccessor;
-import net.pterodactylus.util.collection.filter.Filter;
import net.pterodactylus.util.logging.Logging;
-import net.pterodactylus.util.validation.Validation;
+
+import com.google.common.base.Predicate;
+
import freenet.keys.FreenetURI;
/**
};
/** Filter to remove Sones that have not been downloaded. */
- public static final Filter<Sone> EMPTY_SONE_FILTER = new Filter<Sone>() {
+ public static final Predicate<Sone> EMPTY_SONE_FILTER = new Predicate<Sone>() {
@Override
- public boolean filterObject(Sone sone) {
+ public boolean apply(Sone sone) {
return sone.getTime() != 0;
}
};
- /** Filter that matches all {@link Core#isLocalSone(Sone) local Sones}. */
- public static final Filter<Sone> LOCAL_SONE_FILTER = new Filter<Sone>() {
+ /** Filter that matches all {@link Sone#isLocal() local Sones}. */
+ public static final Predicate<Sone> LOCAL_SONE_FILTER = new Predicate<Sone>() {
@Override
- public boolean filterObject(Sone sone) {
+ public boolean apply(Sone sone) {
return sone.getIdentity() instanceof OwnIdentity;
}
};
/** Filter that matches Sones that have at least one album. */
- public static final Filter<Sone> HAS_ALBUM_FILTER = new Filter<Sone>() {
+ public static final Predicate<Sone> HAS_ALBUM_FILTER = new Predicate<Sone>() {
@Override
- public boolean filterObject(Sone sone) {
+ public boolean apply(Sone sone) {
return !sone.getAlbums().isEmpty();
}
};
* 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;