Use Guava’s predicate instead of utils’ filter.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
index e5ebcf1..80032ad 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - Sone.java - Copyright © 2010 David Roden
+ * Sone - Sone.java - Copyright © 2010–2012 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
@@ -28,14 +28,15 @@ import java.util.concurrent.CopyOnWriteArraySet;
 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.filter.Filter;
 import net.pterodactylus.util.logging.Logging;
 import net.pterodactylus.util.validation.Validation;
+
+import com.google.common.base.Predicate;
+
 import freenet.keys.FreenetURI;
 
 /**
@@ -142,29 +143,29 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        };
 
        /** 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();
                }
        };
@@ -175,6 +176,9 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        /** The ID of this Sone. */
        private final String id;
 
+       /** Whether the Sone is local. */
+       private final boolean local;
+
        /** The identity of this Sone. */
        private Identity identity;
 
@@ -229,9 +233,13 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
         *
         * @param id
         *            The ID of the Sone
+        * @param local
+        *            {@code true} if the Sone is a local Sone, {@code false}
+        *            otherwise
         */
-       public Sone(String id) {
+       public Sone(String id, boolean local) {
                this.id = id;
+               this.local = local;
        }
 
        //
@@ -284,6 +292,16 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        }
 
        /**
+        * Returns whether this Sone is a local Sone.
+        *
+        * @return {@code true} if this Sone is a local Sone, {@code false}
+        *         otherwise
+        */
+       public boolean isLocal() {
+               return local;
+       }
+
+       /**
         * Returns the request URI of this Sone.
         *
         * @return The request URI of this Sone
@@ -791,7 +809,9 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
         */
        public void addAlbum(Album album) {
                Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).check();
-               albums.add(album);
+               if (!albums.contains(album)) {
+                       albums.add(album);
+               }
        }
 
        /**