Bring image-management up to speed.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
index 4bd60cc..aa4a155 100644 (file)
@@ -27,8 +27,10 @@ import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import net.pterodactylus.sone.core.Options;
 import net.pterodactylus.sone.freenet.wot.Identity;
 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 freenet.keys.FreenetURI;
@@ -57,6 +59,15 @@ 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>() {
+
+               @Override
+               public boolean filterObject(Sone sone) {
+                       return sone.getTime() != 0;
+               }
+       };
+
        /** The logger. */
        private static final Logger logger = Logging.getLogger(Sone.class);
 
@@ -103,6 +114,9 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        /** The albums of this Sone. */
        private final List<Album> albums = Collections.synchronizedList(new ArrayList<Album>());
 
+       /** Sone-specific options. */
+       private final Options options = new Options();
+
        /**
         * Creates a new Sone.
         *
@@ -237,7 +251,7 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
         */
        public void setLatestEdition(long latestEdition) {
                if (!(latestEdition > this.latestEdition)) {
-                       logger.log(Level.INFO, "New latest edition %d is not greater than current latest edition %d!", new Object[] { latestEdition, this.latestEdition });
+                       logger.log(Level.FINE, "New latest edition %d is not greater than current latest edition %d!", new Object[] { latestEdition, this.latestEdition });
                        return;
                }
                this.latestEdition = latestEdition;
@@ -391,8 +405,10 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
         * @return This Sone (for method chaining)
         */
        public synchronized Sone setPosts(Collection<Post> posts) {
-               this.posts.clear();
-               this.posts.addAll(posts);
+               synchronized (this) {
+                       this.posts.clear();
+                       this.posts.addAll(posts);
+               }
                return this;
        }
 
@@ -612,7 +628,7 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
         */
        public synchronized void setAlbums(Collection<? extends Album> albums) {
                Validation.begin().isNotNull("Albums", albums).check();
-               albums.clear();
+               this.albums.clear();
                for (Album album : albums) {
                        addAlbum(album);
                }
@@ -629,6 +645,15 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
                albums.remove(album);
        }
 
+       /**
+        * Returns Sone-specific options.
+        *
+        * @return The options of this Sone
+        */
+       public Options getOptions() {
+               return options;
+       }
+
        //
        // FINGERPRINTABLE METHODS
        //