Merge branch 'next' into feature/album-and-image-links
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneParser.java
index 2712bd3..9122852 100644 (file)
@@ -29,6 +29,7 @@ import net.pterodactylus.sone.database.SoneBuilder;
 import net.pterodactylus.util.xml.SimpleXML;
 import net.pterodactylus.util.xml.XML;
 
+import com.google.common.base.Optional;
 import org.w3c.dom.Document;
 
 /**
@@ -266,10 +267,10 @@ public class SoneParser {
                                        logger.log(Level.WARNING, String.format("Downloaded Sone %s contains invalid album!", sone));
                                        return null;
                                }
-                               Album parent = null;
+                               Optional<Album> parent = Optional.absent();
                                if (parentId != null) {
                                        parent = core.getAlbum(parentId);
-                                       if (parent == null) {
+                                       if (!parent.isPresent()) {
                                                logger.log(Level.WARNING, String.format("Downloaded Sone %s has album with invalid parent!", sone));
                                                return null;
                                        }
@@ -282,8 +283,8 @@ public class SoneParser {
                                                .setTitle(title)
                                                .setDescription(description)
                                                .update();
-                               if (parent != null) {
-                                       parent.addAlbum(album);
+                               if (parent.isPresent()) {
+                                       parent.get().addAlbum(album);
                                } else {
                                        topLevelAlbums.add(album);
                                }
@@ -325,16 +326,13 @@ public class SoneParser {
                }
 
                /* okay, apparently everything was parsed correctly. Now import. */
-               /* atomic setter operation on the Sone. */
-               synchronized (sone) {
-                       sone.setProfile(profile);
-                       sone.setPosts(posts);
-                       sone.setReplies(replies);
-                       sone.setLikePostIds(likedPostIds);
-                       sone.setLikeReplyIds(likedReplyIds);
-                       for (Album album : topLevelAlbums) {
-                               sone.getRootAlbum().addAlbum(album);
-                       }
+               sone.setProfile(profile);
+               sone.setPosts(posts);
+               sone.setReplies(replies);
+               sone.setLikePostIds(likedPostIds);
+               sone.setLikeReplyIds(likedReplyIds);
+               for (Album album : topLevelAlbums) {
+                       sone.getRootAlbum().addAlbum(album);
                }
 
                return sone;