X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneParser.java;h=9122852764b48067106617af42e2588f3d8e5ec1;hb=cc18e5878bc71081da5137eb777d91821c3f4cce;hp=2712bd36d6ddc4d9cc1c31bf419701c1b6f7eec9;hpb=32998f6979928e57b9b7a4eac4dabe668a821471;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/SoneParser.java b/src/main/java/net/pterodactylus/sone/core/SoneParser.java index 2712bd3..9122852 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneParser.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneParser.java @@ -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 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;